diff --git a/build.gradle b/build.gradle index 5bac80b64..a3892da96 100644 --- a/build.gradle +++ b/build.gradle @@ -69,6 +69,7 @@ allprojects { implementation 'org.swingexplorer:swag:1.0' implementation 'net.java.dev.jna:jna:5.4.0' implementation 'org.apache.tomcat:tomcat-catalina:8.5.72' + implementation 'org.apache.tomcat:tomcat-websocket:8.5.72' implementation 'io.socket:socket.io-client:0.7.0' implementation 'com.fr.third:fine-third:' + frVersion implementation 'com.fr.core:fine-core:' + frDevVersion diff --git a/designer-base/src/main/java/com/fr/common/exception/ThrowableHandler.java b/designer-base/src/main/java/com/fr/common/exception/ThrowableHandler.java new file mode 100644 index 000000000..14d2dcc81 --- /dev/null +++ b/designer-base/src/main/java/com/fr/common/exception/ThrowableHandler.java @@ -0,0 +1,12 @@ +package com.fr.common.exception; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/7 + */ +public interface ThrowableHandler { + + boolean process(Throwable e); + +} 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 9d84e25ba..1f39f024d 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -53,7 +53,8 @@ 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.apache.log4j.FileAppender; +import com.fr.third.apache.logging.log4j.core.appender.FileAppender; +import com.fr.third.apache.logging.log4j.core.layout.PatternLayout; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContextCallback; @@ -324,18 +325,18 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (!new File(fileName).exists()) { StableUtils.makesureFileExist(new File(fileName)); } - LogHandler handler = new LogHandler() { - final FileAppender appender = new FileAppender( - new com.fr.third.apache.log4j.PatternLayout("%d{HH:mm:ss} %t %p [%c] %m%n"), - fileName - ); + LogHandler handler = new LogHandler() { + final FileAppender appender = FileAppender.newBuilder(). + setName(FileAppender.class.getSimpleName()). + setLayout(PatternLayout.newBuilder().withPattern("%d{HH:mm:ss} %t %p [%c] %m%n").build()). + withFileName(fileName).build(); @Override public FileAppender getHandler() { return appender; } }; - + handler.getHandler().start(); FineLoggerFactory.getLogger().addLogAppender(handler); } catch (SecurityException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); 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 303d9fd81..c0797e946 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 @@ -29,7 +29,6 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.VerticalFlowLayout; -import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.os.impl.SupportOSImpl; @@ -45,14 +44,12 @@ import com.fr.locale.InterProviderFactory; import com.fr.log.FineLoggerFactory; import com.fr.stable.Constants; import com.fr.stable.os.OperatingSystem; -import com.fr.third.apache.log4j.Level; +import com.fr.third.apache.logging.log4j.Level; import com.fr.transaction.Configurations; 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; diff --git a/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java new file mode 100644 index 000000000..f23b5b078 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java @@ -0,0 +1,104 @@ +package com.fr.design.cell; + +import com.fr.base.CellBorderSourceFlag; +import com.fr.base.CellBorderStyle; +import com.fr.base.Style; +import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; +import com.fr.report.cell.TemplateCellElement; + +import javax.swing.JPanel; +import java.awt.Dimension; +import java.awt.GridLayout; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/3 + */ +public class CellRectangleStylePreviewPane extends JPanel { + private static final int ROW_COUNT = 2; + private static final int COLUMN_COUNT = 2; + + private final TemplateCellElement[][] cellElementGrid = new TemplateCellElement[ROW_COUNT][COLUMN_COUNT]; + private final int[][] borderSourceFlags = new int[ROW_COUNT][COLUMN_COUNT]; + private final CellStylePreviewPane[][] cellStylePreviewPaneGrid = new CellStylePreviewPane[ROW_COUNT][COLUMN_COUNT]; + + public CellRectangleStylePreviewPane(boolean supportInnerBorder) { + setLayout(new GridLayout(2, 2)); + + for (int r = 0; r < ROW_COUNT; r++) { + for (int c = 0; c < COLUMN_COUNT; c++) { + CellStylePreviewPane pane = new CellStylePreviewPane(); + TemplateCellElement cellElement = DefaultThemedTemplateCellElementCase.createInstance(c, r); + int flags = CellBorderSourceFlag.INVALID_BORDER_SOURCE; + if (supportInnerBorder) { + flags = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r != 0) { + flags |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r != ROW_COUNT - 1) { + flags |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + if (c != 0) { + flags |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c != COLUMN_COUNT - 1) { + flags |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + } + + + pane.setStyle(cellElement.getStyle()); + add(pane); + + cellElementGrid[r][c] = cellElement; + borderSourceFlags[r][c] = flags; + cellStylePreviewPaneGrid[r][c] = pane; + } + } + } + + public void setPlainText(String text) { + cellStylePreviewPaneGrid[0][1].setPaintText(text); + cellStylePreviewPaneGrid[1][1].setPaintText(text); + repaint(); + } + + public void setStyle(Style style, CellBorderStyle borderStyle) { + for (int i = 0; i < ROW_COUNT; i++) { + for (int j = 0; j < COLUMN_COUNT; j++) { + CellStylePreviewPane pane = cellStylePreviewPaneGrid[i][j]; + TemplateCellElement cellElement = cellElementGrid[i][j]; + int flag = borderSourceFlags[i][j]; + cellElement.setStyle(CellBorderSourceFlag.deriveBorderedStyle(style, borderStyle, flag)); + + pane.setStyle(cellElement.getStyle()); + } + } + repaint(); + } + + @Override + public void setPreferredSize(Dimension preferredSize) { + super.setPreferredSize(preferredSize); + int hw = preferredSize.width / 2; + int hh = preferredSize.height / 2; + cellStylePreviewPaneGrid[0][0].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[0][1].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[1][0].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[1][1].setPreferredSize(new Dimension(hw, hh)); + } + + @Override + public Dimension getPreferredSize() { + Dimension d00 = cellStylePreviewPaneGrid[0][0].getPreferredSize(); + Dimension d01 = cellStylePreviewPaneGrid[0][1].getPreferredSize(); + Dimension d10 = cellStylePreviewPaneGrid[1][0].getPreferredSize(); + Dimension d11 = cellStylePreviewPaneGrid[1][1].getPreferredSize(); + + int width = Math.max(d00.width + d01.width, d10.width + d11.width); + int height = Math.max(d00.height + d10.height, d01.height + d11.height); + + return new Dimension(width, height); + } +} diff --git a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java index cb6cfc8d5..fb039fa4a 100644 --- a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java @@ -1,19 +1,26 @@ package com.fr.design.cell; +import com.fr.base.BaseUtils; +import com.fr.base.GraphHelper; import com.fr.base.NameStyle; import com.fr.base.ScreenResolution; import com.fr.base.Style; +import com.fr.general.FRFont; import com.fr.general.IOUtils; +import com.fr.stable.unit.PT; import javax.swing.JPanel; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.util.List; /** * @author Starryi @@ -22,6 +29,7 @@ import java.awt.image.BufferedImage; */ public class CellStylePreviewPane extends JPanel { + public static final int MINIMUM_HEIGHT = 40; private static final BufferedImage transparentBackgroundImage = IOUtils.readImage("/com/fr/design/images/transparent_background.png"); private final float transparentBackgroundWidth; private final float transparentBackgroundHeight; @@ -31,16 +39,24 @@ public class CellStylePreviewPane extends JPanel { public CellStylePreviewPane() { transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); + setPreferredSize(new Dimension(0, 0)); + } + + public void setPaintText(String paintText) { + this.paintText = paintText; + repaint(); } public void setStyle(Style style) { this.style = style; - if (style instanceof NameStyle) { - paintText = ((NameStyle) style).getName(); - } repaint(); } + public void setStyle(NameStyle style) { + paintText = style.getName(); + setStyle(style.getRealStyle()); + } + @Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; @@ -107,11 +123,45 @@ public class CellStylePreviewPane extends JPanel { Style.paintContent(g2d, paintText, style, width, height, resolution); - Style.paintBorder(g2d, style, width, height); + Style.paintBorder(g2d, style, + width - GraphHelper.getLineStyleSize(style.getBorderRight()) / 2F, + height - GraphHelper.getLineStyleSize(style.getBorderBottom()) / 2F); } @Override - public Dimension getMinimumSize() { - return getPreferredSize(); + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + int width = size.width; + int height = size.height; + + if (height != 0) { + // 使用者设置了一个高度 + return size; + } else if (width == 0) { + // 使用者未设置任何尺寸 + return new Dimension(width, MINIMUM_HEIGHT); + } else { + // 使用者设置了宽度,但未设置高度 + return getAutoWrapContentPreferredSize(width, height); + } + } + + private Dimension getAutoWrapContentPreferredSize(int width, int height) { + int resolution = ScreenResolution.getScreenResolution(); + + // 计算文本区域高度 + final FRFont frFont = style.getFRFont(); + final Font rfont = frFont.applyResolutionNP(resolution); + final FontMetrics metrics = GraphHelper.getFontMetrics(rfont); + final int textLineHeight = metrics.getHeight(); + final double textLineSpacing = PT.pt2pix(style.getLineSpacing(), resolution); + + List textLineList = BaseUtils.getLineTextList(paintText, style, rfont, height, width, resolution); + + double textLinesHeight = textLineList.size() * textLineHeight + Math.max(0, textLineList.size() - 1) * textLineSpacing; + + height = (int) Math.max(MINIMUM_HEIGHT, textLinesHeight); + + return new Dimension(width, height); } } diff --git a/designer-base/src/main/java/com/fr/design/config/DesignerProperties.java b/designer-base/src/main/java/com/fr/design/config/DesignerProperties.java new file mode 100644 index 000000000..d14c7938a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/config/DesignerProperties.java @@ -0,0 +1,52 @@ +package com.fr.design.config; + +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Properties; + +public class DesignerProperties { + private static DesignerProperties holder = null; + private boolean supportLoginEntry = true; + + public DesignerProperties() { + String filePath = StableUtils.pathJoin(StableUtils.getInstallHome(), "/config/config.properties"); + InputStream is = null; + try { + is = new BufferedInputStream(new FileInputStream(filePath)); + Properties ps = new Properties(); + ps.load(is); + this.initProperties(ps); + } catch (FileNotFoundException e) { + // ignore + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } finally { + IOUtils.close(is); + } + } + + public static DesignerProperties getInstance() { + if (holder == null) { + holder = new DesignerProperties(); + } + return holder; + } + + private void initProperties(Properties ps) { + String supportLoginEntry = ps.getProperty("supportLoginEntry"); + if (StringUtils.isNotEmpty(supportLoginEntry)) { + this.supportLoginEntry = Boolean.valueOf(supportLoginEntry); + } + } + + public boolean isSupportLoginEntry() { + return supportLoginEntry; + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java index f65610526..99a294fdd 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java @@ -1,12 +1,12 @@ package com.fr.design.data.datapane; import com.fr.base.TableData; -import com.fr.concurrent.NamedThreadFactory; import com.fr.data.core.DataCoreUtils; import com.fr.data.core.db.DBUtils; import com.fr.data.core.db.TableProcedure; import com.fr.data.core.db.dialect.Dialect; import com.fr.data.core.db.dialect.DialectFactory; +import com.fr.data.impl.Connection; import com.fr.data.impl.DBTableData; import com.fr.data.operator.DataOperator; import com.fr.design.DesignerEnvManager; @@ -19,7 +19,7 @@ import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.tabledata.Prepare4DataSourceChange; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.icombobox.FilterableComboBoxModel; -import com.fr.design.gui.icombobox.SearchPreTaskTreeComboBox; +import com.fr.design.gui.icombobox.TableSearchTreeComboBox; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBoxEditor; import com.fr.design.gui.icombobox.UIComboBoxRenderer; @@ -40,11 +40,6 @@ import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.server.connection.DBConnectAuth; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.util.Collections; -import java.util.concurrent.CancellationException; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -58,21 +53,20 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeCellRenderer; -import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; +import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; +import java.util.concurrent.CancellationException; /** * @author zhou @@ -97,41 +91,12 @@ public class ChoosePane extends BasicBeanPane implements Refresha /** * 表名 */ - protected SearchPreTaskTreeComboBox tableNameComboBox; - - private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor(new NamedThreadFactory("ChoosePane")); + protected TableSearchTreeComboBox tableNameComboBox; private SwingWorker populateWorker; private SwingWorker, Void> initWorker; - private PopupMenuListener popupMenuListener = new PopupMenuListener() { - - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - FutureTask task = new FutureTask(new Callable() { - @Override - public Void call() throws Exception { - calculateTableDataNames(); - return null; - } - }); - tableNameComboBox.setPreSearchTask(task); - SERVICE.submit(task); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - // Do nothing - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - // Do nothing - } - }; - - private PopupMenuListener listener = new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { @@ -181,7 +146,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha schemaBox = new StringUIComboBox(); schemaBox.setEditor(new ComboBoxEditor()); - tableNameComboBox = new SearchPreTaskTreeComboBox(new JTree(new DefaultMutableTreeNode()), tableNameTreeRenderer, false); + tableNameComboBox = new TableSearchTreeComboBox(this, new JTree(new DefaultMutableTreeNode()), tableNameTreeRenderer); tableNameComboBox.setEditable(true); tableNameComboBox.setRenderer(listCellRenderer); registerDSChangeListener(); @@ -198,7 +163,6 @@ public class ChoosePane extends BasicBeanPane implements Refresha }); schemaBox.addPopupMenuListener(listener); addFocusListener(); - this.tableNameComboBox.addPopupMenuListener(popupMenuListener); } protected void addDSBoxListener() { @@ -355,7 +319,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha GUICoreUtils.setSelectedItemQuietly(tableNameComboBox, -1); } - protected com.fr.data.impl.Connection getConnection() { + public Connection getConnection() { String selectedDSName = this.getDSName(); if (StringUtils.isEmpty(selectedDSName)) { return null; // peter:选中了当前的零长度的节点,直接返回. @@ -455,56 +419,6 @@ public class ChoosePane extends BasicBeanPane implements Refresha return "choosepane"; } - protected void calculateTableDataNames() { - JTree tree = tableNameComboBox.getTree(); - if (tree == null) { - return; - } - DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); - rootTreeNode.removeAllChildren(); - - String selectedDSName = this.getDSName(); - com.fr.data.impl.Connection selectedDatabase = this.getConnection(); - if (selectedDatabase == null) { - return; - } - try { - String schema = StringUtils.isEmpty(this.schemaBox.getSelectedItem()) ? null : this.schemaBox.getSelectedItem(); - TableProcedure[] sqlTableArray = DataCoreUtils.getTables(selectedDatabase, TableProcedure.TABLE, schema, DesignerEnvManager.getEnvManager().isOracleSystemSpace()); - if (sqlTableArray.length > 0) { - ExpandMutableTreeNode tableTreeNode = new ExpandMutableTreeNode(selectedDSName + "-" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_SQL_Table")); - rootTreeNode.add(tableTreeNode); - for (int i = 0; i < sqlTableArray.length; i++) { - ExpandMutableTreeNode tableChildTreeNode = new ExpandMutableTreeNode(sqlTableArray[i]); - tableTreeNode.add(tableChildTreeNode); - } - } - TableProcedure[] sqlViewArray = DataCoreUtils.getTables(selectedDatabase, TableProcedure.VIEW, schema, DesignerEnvManager.getEnvManager().isOracleSystemSpace()); - if (sqlViewArray.length > 0) { - ExpandMutableTreeNode viewTreeNode = new ExpandMutableTreeNode(selectedDSName + "-" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_SQL_View")); - rootTreeNode.add(viewTreeNode); - for (int i = 0; i < sqlViewArray.length; i++) { - ExpandMutableTreeNode viewChildTreeNode = new ExpandMutableTreeNode(sqlViewArray[i]); - viewTreeNode.add(viewChildTreeNode); - } - } - ((DefaultTreeModel) tree.getModel()).reload(); - // daniel 展开所有tree - TreeNode root = (TreeNode) tree.getModel().getRoot(); - TreePath parent = new TreePath(root); - TreeNode node = (TreeNode) parent.getLastPathComponent(); - for (Enumeration e = node.children(); e.hasMoreElements(); ) { - TreeNode n = (TreeNode) e.nextElement(); - TreePath path = parent.pathByAddingChild(n); - tree.expandPath(path); - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Failed"), JOptionPane.ERROR_MESSAGE); - } - } - /** * 创建选中的数据集数据 * @@ -558,22 +472,23 @@ public class ChoosePane extends BasicBeanPane implements Refresha return tableData; } - protected String getDSName() { + public String getDSName() { return this.dsNameComboBox.getSelectedItem(); } + public String getSchema() { + return this.schemaBox.getSelectedItem(); + } + protected void failedToFindTable() { // Do nothing } protected String getTableName() { String tableName = ""; - Object obj = this.tableNameComboBox.getSelectedItemObject(); + Object obj = this.tableNameComboBox.getSelectedItem(); if (obj == null) { - obj = this.tableNameComboBox.getSelectedItem(); - if (obj == null) { - obj = this.tableNameComboBox.getEditor().getItem(); - } + obj = this.tableNameComboBox.getEditor().getItem(); } if (obj instanceof TreePath) { Object tp = ((ExpandMutableTreeNode) ((TreePath) obj).getLastPathComponent()).getUserObject(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePaneSupportFormula.java b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePaneSupportFormula.java index 14d0431e2..8fc62cd77 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePaneSupportFormula.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePaneSupportFormula.java @@ -83,7 +83,7 @@ public class ChoosePaneSupportFormula extends ChoosePane { * * @return */ - protected String getDSName() { + public String getDSName() { String selectedDSName = null; String item = Utils.objectToString(this.dsNameComboBox.getEditor().getItem()); // 没有选中的列表项 那么看看是不是手输值 diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java new file mode 100644 index 000000000..204123095 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java @@ -0,0 +1,147 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.pool.DBCPConnectionPoolAttr; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.editor.IntegerEditor; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.stable.StringUtils; + +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; + +/** + * @author xiqiu + * @date 2021/11/22 + * @description + */ +public class AdvancePane extends BasicPane { + private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); + private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); + private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); + private SpecialUITextField DBCP_VALIDATION_QUERY = new SpecialUITextField(); + + + public AdvancePane() { + + DBCP_VALIDATION_QUERY.addFocusListener(new JTextFieldHintListener(DBCP_VALIDATION_QUERY)); + ; + double p = TableLayout.PREFERRED; + DBCP_VALIDATION_QUERY.setColumns(15); + double[] rowSizeDbcp = {p, p, p, p}; + double[] columnDbcp = {p, p}; + Component[][] comps = { + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, + {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT} + }; + + JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSizeDbcp, columnDbcp, 11, 11); + this.add(contextPane); + this.setPreferredSize(new Dimension(630, 120)); + this.setLayout(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); + } + + + public void populate(JDBCDatabaseConnection jdbcDatabase) { + DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); + if (dbcpAttr == null) { + dbcpAttr = new DBCPConnectionPoolAttr(); + jdbcDatabase.setDbcpAttr(dbcpAttr); + } + this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); + this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); + this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); + this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); + + } + + public void update(JDBCDatabaseConnection jdbcDatabase) { + DBCPConnectionPoolAttr dbcpAttr = jdbcDatabase.getDbcpAttr(); + if (dbcpAttr == null) { + dbcpAttr = new DBCPConnectionPoolAttr(); + jdbcDatabase.setDbcpAttr(dbcpAttr); + } + dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); + dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); + dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); + dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Advanced_Setup"); + } + + + private class JTextFieldHintListener implements FocusListener { + private SpecialUITextField textField; + + public JTextFieldHintListener(SpecialUITextField jTextField) { + this.textField = jTextField; + } + + @Override + public void focusGained(FocusEvent e) { + //获取焦点时,清空提示内容 + String temp = textField.getText(); + textField.setForeground(Color.BLACK); + textField.setTextOrigin(temp); + + } + + @Override + public void focusLost(FocusEvent e) { + //失去焦点时,没有输入内容,显示提示内容 + String temp = textField.getTextOrigin(); + textField.setText(temp); + } + } + + private class SpecialUITextField extends UITextField { + + @Override + public String getText() { + String text = super.getText(); + if (isUseless(text)) { + return StringUtils.EMPTY; + } + return text; + } + + @Override + public void setText(String text) { + if (isUseless(text)) { + this.setForeground(Color.GRAY); + super.setText(Toolkit.i18nText("Fine-Design_Dbcp_Default_Query")); + } else { + this.setForeground(Color.BLACK); + super.setText(text); + } + } + + public String getTextOrigin() { + return super.getText(); + } + + public void setTextOrigin(String text) { + super.setText(text); + } + + private boolean isUseless(String text) { + return text == null || text.isEmpty() || Toolkit.i18nText("Fine-Design_Dbcp_Default_Query").equals(text); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java index f65b6dc12..86e7633be 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DBCPAttrPane.java @@ -20,6 +20,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Window; @@ -45,13 +46,8 @@ public class DBCPAttrPane extends BasicPane { private static final int EMPTY_FETCHSIZE = -2; // carl:DBCP的一些属性 private IntegerEditor DBCP_INITIAL_SIZE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_ACTIVE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_IDLE = new IntegerEditor(); private IntegerEditor DBCP_MIN_IDLE = new IntegerEditor(); - private IntegerEditor DBCP_MAX_WAIT = new IntegerEditor(); - private UITextField DBCP_VALIDATION_QUERY = new UITextField(); - private UIComboBox DBCP_TESTONBORROW = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); private UIComboBox DBCP_TESTONRETURN = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); private UIComboBox DBCP_TESTWHILEIDLE = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_No"), Toolkit.i18nText("Fine-Design_Basic_Yes")}); @@ -75,25 +71,19 @@ public class DBCPAttrPane extends BasicPane { defaultPane = this; // JPanel northFlowPane - northFlowPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr")); - northFlowPane.setPreferredSize(new Dimension(630, 320)); + northFlowPane = FRGUIPaneFactory.createTopVerticalTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_ConnectionPool_Attr")); + northFlowPane.setPreferredSize(new Dimension(630, 330)); defaultPane.add(northFlowPane, BorderLayout.NORTH); - DBCP_VALIDATION_QUERY.setColumns(15); // ContextPane double f = TableLayout.FILL; // double p = TableLayout.PREFERRED; - double[] rowSize = {f, f, f, f, f, f, f, f, f, f, f, f}; + double[] rowSize = {f, f, f, f, f, f, f}; double[] columnSize = {f, f}; Component[][] comps = { {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Initial_Size") + ":", SwingConstants.RIGHT), DBCP_INITIAL_SIZE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Idle") + ":", SwingConstants.RIGHT), DBCP_MAX_IDLE}, {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Min_Idle") + ":", SwingConstants.RIGHT), DBCP_MIN_IDLE}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Max_Wait_Time") + ":", SwingConstants.RIGHT), DBCP_MAX_WAIT}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, - {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Borrow") + ":", SwingConstants.RIGHT), DBCP_TESTONBORROW}, {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_On_Return") + ":", SwingConstants.RIGHT), DBCP_TESTONRETURN}, {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Test_While_Idle") + ":", SwingConstants.RIGHT), DBCP_TESTWHILEIDLE}, {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Evictionruns_millis") + ":", SwingConstants.RIGHT), @@ -102,8 +92,13 @@ public class DBCPAttrPane extends BasicPane { {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Connection_Pool_Mix_Evictable_Idle_Time_Millis") + ":", SwingConstants.RIGHT), DBCP_MINEVICTABLEIDLETIMEMILLIS}}; - JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 4); + JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSize, columnSize, 10, 10); northFlowPane.add(contextPane); + JPanel boxFlowInnerContainer = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(0, 5, 5); + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Dbcp_Warning")); + uiLabel.setForeground(Color.RED); + boxFlowInnerContainer.add(uiLabel); + northFlowPane.add(boxFlowInnerContainer); } public void populate(JDBCDatabaseConnection jdbcDatabase) { @@ -113,12 +108,7 @@ public class DBCPAttrPane extends BasicPane { jdbcDatabase.setDbcpAttr(dbcpAttr); } this.DBCP_INITIAL_SIZE.setValue(dbcpAttr.getInitialSize()); - this.DBCP_MAX_ACTIVE.setValue(dbcpAttr.getMaxActive()); - this.DBCP_MAX_IDLE.setValue(dbcpAttr.getMaxIdle()); - this.DBCP_MAX_WAIT.setValue(dbcpAttr.getMaxWait()); this.DBCP_MIN_IDLE.setValue(dbcpAttr.getMinIdle()); - this.DBCP_VALIDATION_QUERY.setText(dbcpAttr.getValidationQuery()); - this.DBCP_TESTONBORROW.setSelectedIndex(dbcpAttr.isTestOnBorrow() ? 1 : 0); this.DBCP_TESTONRETURN.setSelectedIndex(dbcpAttr.isTestOnReturn() ? 1 : 0); this.DBCP_TESTWHILEIDLE.setSelectedIndex(dbcpAttr.isTestWhileIdle() ? 1 : 0); this.DBCP_MINEVICTABLEIDLETIMEMILLIS.setValue(dbcpAttr.getMinEvictableIdleTimeMillis() / TIME_MULTIPLE); @@ -141,12 +131,7 @@ public class DBCPAttrPane extends BasicPane { jdbcDatabase.setDbcpAttr(dbcpAttr); } dbcpAttr.setInitialSize(this.DBCP_INITIAL_SIZE.getValue().intValue()); - dbcpAttr.setMaxActive(this.DBCP_MAX_ACTIVE.getValue().intValue()); - dbcpAttr.setMaxIdle(this.DBCP_MAX_IDLE.getValue().intValue()); - dbcpAttr.setMaxWait(this.DBCP_MAX_WAIT.getValue().intValue()); dbcpAttr.setMinIdle(this.DBCP_MIN_IDLE.getValue().intValue()); - dbcpAttr.setValidationQuery(this.DBCP_VALIDATION_QUERY.getText()); - dbcpAttr.setTestOnBorrow(this.DBCP_TESTONBORROW.getSelectedIndex() == 0 ? false : true); dbcpAttr.setTestOnReturn(this.DBCP_TESTONRETURN.getSelectedIndex() == 0 ? false : true); dbcpAttr.setTestWhileIdle(this.DBCP_TESTWHILEIDLE.getSelectedIndex() == 0 ? false : true); dbcpAttr.setMinEvictableIdleTimeMillis(((Number) this.DBCP_MINEVICTABLEIDLETIMEMILLIS.getValue()).intValue() * TIME_MULTIPLE); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index e55aaa2dd..91e8006d1 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -14,11 +14,11 @@ import com.fr.data.solution.processor.SolutionProcessor; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.scrollruler.ModLineBorder; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.log.FineLoggerFactory; import com.fr.rpc.ExceptionHandler; @@ -34,6 +34,7 @@ import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.UIManager; @@ -60,6 +61,8 @@ import java.util.concurrent.ExecutionException; * Database Connection pane. */ public abstract class DatabaseConnectionPane extends BasicBeanPane { + private static int MAX_MAIN_PANEL_HEIGHT = 430; + private static int MAX_MAIN_PANEL_WIDTH = 675; private UILabel message; private UIButton okButton; @@ -305,6 +308,10 @@ public abstract class DatabaseConnectionPane MAX_MAIN_PANEL_HEIGHT || mainPanel.getPreferredSize().width > MAX_MAIN_PANEL_WIDTH) { + UIScrollPane jp = new + UIScrollPane(mainPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + jp.setPreferredSize(new Dimension(MAX_MAIN_PANEL_WIDTH, MAX_MAIN_PANEL_HEIGHT)); + northPane.add(jp, BorderLayout.CENTER); + } else { + mainPanel.setPreferredSize(new Dimension(MAX_MAIN_PANEL_WIDTH, MAX_MAIN_PANEL_HEIGHT)); + northPane.add(mainPanel, BorderLayout.CENTER); + } // ChartSet String[] defaultEncode = new String[]{Toolkit.i18nText("Fine-Design_Encode_Auto")}; charSetComboBox = new UIComboBox(ArrayUtils.addAll(defaultEncode, EncodeConstants.ENCODING_ARRAY)); @@ -406,6 +426,7 @@ public abstract class DatabaseConnectionPane { private static JDBCDefPane jdbcDefPane = new JDBCDefPane(); private static DBCPAttrPane dbcpAttrPane = new DBCPAttrPane(); + private static AdvancePane advancePane = new AdvancePane(); @Override protected JPanel mainPanel() { @@ -425,15 +446,22 @@ public abstract class DatabaseConnectionPane template) { - String name = template.getTemplateName(); + String name = TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()); if (!template.isSaved() && !name.endsWith(" *")) { name += " *"; } diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index 363eb1ab0..bc5e0da6b 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -12,7 +12,11 @@ import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.lock.LockInfoUtils; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrameFileDealerPane; +import com.fr.design.lock.LockInfoDialog; +import com.fr.design.mainframe.JTemplate; import com.fr.file.FILE; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; @@ -21,12 +25,15 @@ import com.fr.form.fit.web.editpreview.FileLockStateObservable; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; +import com.fr.workspace.base.UserInfo; import com.fr.stable.ArrayUtils; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; +import com.fr.report.lock.LockInfoOperator; +import java.util.UUID; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; @@ -50,6 +57,8 @@ import java.util.Enumeration; import java.util.Objects; import java.util.Observable; import java.util.Observer; +import org.jetbrains.annotations.Nullable; + import static javax.swing.JOptionPane.WARNING_MESSAGE; import static javax.swing.JOptionPane.YES_NO_OPTION; @@ -113,6 +122,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (toolBarStateChangeListener != null) { toolBarStateChangeListener.stateChange(); } + DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(reportletsTree.getSelectedFileNode()); } }; // lx: add mouse listener @@ -216,15 +226,44 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (node == null) { return; } + String reportPath = reportletsTree.getSelectedTemplatePath(); + final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath); String lock = node.getLock(); - if (lock != null && !lock.equals(node.getUserID())) { + boolean showLockInfo = LockInfoUtils.isCompatibleOperator() + || LockInfoUtils.unableGetLockInfo() + || WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(selectedFilePath) + ? (lock != null && !lock.equals(node.getUserID())) + : WorkContext.getCurrent().get(LockInfoOperator.class).isTplLocked(selectedFilePath); + if (showLockInfo) { + UserInfo userInfo = WorkContext.getCurrent().get(LockInfoOperator.class).getUserInfo(selectedFilePath); + node.setLock(UUID.randomUUID().toString()); + // 对于开发者预览占位锁定 定位到tab中 + checkDevelopForBiddenTemplate(selectedFilePath); + LockInfoDialog.show(userInfo); return; + } else { + node.setLock(null); } - String reportPath = reportletsTree.getSelectedTemplatePath(); - final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath); DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); } + private void checkDevelopForBiddenTemplate(String selectedFilePath) { + JTemplate template = getOpenedTemplate(selectedFilePath); + if (template != null && template.isForbidden()) { + DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); + } + } + + @Nullable + private JTemplate getOpenedTemplate(String path) { + for (JTemplate template : HistoryTemplateListCache.getInstance().getHistoryList()) { + if (ComparatorUtils.equals(template.getEditingFILE().getPath(), path)) { + return template; + } + } + return null; + } + /** * 打开文件夹 */ @@ -248,6 +287,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { // 刷新远程文件夹权限 NodeAuthProcessor.getInstance().refresh(); reportletsTree.refresh(); + DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(null); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully") + "!"); } 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 27018e6e0..74bf3fe76 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 @@ -290,6 +290,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { initTextPane(); initTipsPane(); initVariableTreeAndDescriptionArea(); + refocusInWindow(); + } + + public void refocusInWindow() { + SwingUtilities.invokeLater(() -> formulaTextArea.requestFocusInWindow()); } private void initVariableTreeAndDescriptionArea() { diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/AbstractAttrNoScrollPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/AbstractAttrNoScrollPane.java index a9321879c..15d50d00c 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/AbstractAttrNoScrollPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/AbstractAttrNoScrollPane.java @@ -3,6 +3,8 @@ package com.fr.design.gui.frpane; import com.fr.design.dialog.BasicPane; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; +import com.fr.design.event.ComponentChangeListener; +import com.fr.design.event.ComponentChangeObserver; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.stable.StringUtils; @@ -103,6 +105,15 @@ public abstract class AbstractAttrNoScrollPane extends BasicPane { } }); } + if(tmpComp instanceof ComponentChangeObserver){ + ComponentChangeObserver uiChangeableObserver = ((ComponentChangeObserver)tmpComp); + uiChangeableObserver.registerChangeListener(new ComponentChangeListener() { + @Override + public void initListener(Container changedComponent) { + AbstractAttrNoScrollPane.this.initListener(changedComponent); + } + }); + } } } diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/TreeSettingPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/TreeSettingPane.java index ba75cce9d..db453c99f 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/TreeSettingPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/TreeSettingPane.java @@ -127,7 +127,7 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI { buildBox.setSelectedIndex(1); TableDataDictionary dictionary = treeEditor.getDictionary(); autoBuildPane.populate(dictionary); - } else if (treeEditor.isLayerBuild()) { + } else if (treeEditor.isFastLayerBuild()) { buildBox.setSelectedIndex(0); java.util.List layerConfigList = treeEditor.getLayerConfigs(); LayerConfig[] layerConfigs = new LayerConfig[layerConfigList.size()]; @@ -156,12 +156,12 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI { if (buildBox.getSelectedIndex() == 1) { TableDataDictionary dictionary = this.autoBuildPane.update(); te.setAutoBuild(true); - te.setLayerBuild(false); + te.setFastLayerBuild(false); te.setDictionary(dictionary); te.setNodeOrDict(dictionary); } else if (buildBox.getSelectedIndex() == 2) { te.setAutoBuild(false); - te.setLayerBuild(false); + te.setFastLayerBuild(false); NameObject no = this.controlPane.update(); if (no != null) { TreeEditor editor = (TreeEditor) no.getObject(); @@ -181,7 +181,7 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI { } else { LayerConfig[] configs = (LayerConfig[]) layerDataControlPane.update().getObject(); te.setAutoBuild(false); - te.setLayerBuild(true); + te.setFastLayerBuild(true); te.setLayerConfigs(Arrays.asList(configs)); } return te; @@ -215,12 +215,12 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI { if (buildBox.getSelectedIndex() == 1) { TableDataDictionary dictionary = this.autoBuildPane.update(); tcb.setAutoBuild(true); - tcb.setLayerBuild(false); + tcb.setFastLayerBuild(false); tcb.setDictionary(dictionary); tcb.setNodeOrDict(dictionary); } else if (buildBox.getSelectedIndex() == 2) { tcb.setAutoBuild(false); - tcb.setLayerBuild(false); + tcb.setFastLayerBuild(false); NameObject no = this.controlPane.update(); if (no != null) { if (no.getObject() instanceof TreeComboBoxEditor) { @@ -244,7 +244,7 @@ public class TreeSettingPane extends BasicPane implements DataCreatorUI { }else { LayerConfig[] configs = (LayerConfig[]) layerDataControlPane.update().getObject(); tcb.setAutoBuild(false); - tcb.setLayerBuild(true); + tcb.setFastLayerBuild(true); tcb.setLayerConfigs(Arrays.asList(configs)); } return tcb; diff --git a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java index e294d8022..0ddd3e22d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java @@ -58,7 +58,7 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser super(locText, b); setUI(new UICheckBoxUI()); initListener(); - this.markMnemonic=markMnemonic; + this.markMnemonic = markMnemonic; } public UICheckBox(String text, Icon icon) { @@ -100,6 +100,10 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser } + public void removeChangeListener() { + uiObserverListener = null; + } + @Override public void setGlobalName(String name) { checkboxName = name; diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java index 8fe79d41e..c12239447 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java @@ -248,7 +248,7 @@ public class FRTreeComboBox extends UIComboBox { private static TreePopup treePopup; - private static class FRTreeComboBoxUI extends BasicComboBoxUI implements MouseListener{ + protected static class FRTreeComboBoxUI extends BasicComboBoxUI implements MouseListener{ private boolean isRollover = false; public FRTreeComboBoxUI() { @@ -535,7 +535,7 @@ public class FRTreeComboBox extends UIComboBox { public class FrTreeSearchComboBoxEditor extends UIComboBoxEditor implements DocumentListener { private volatile boolean setting = false; private FRTreeComboBox comboBox; - private Object item; + protected Object item; public FrTreeSearchComboBoxEditor(FRTreeComboBox comboBox) { super(); diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java deleted file mode 100644 index 2d936d896..000000000 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/SearchPreTaskTreeComboBox.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.fr.design.gui.icombobox; - -import com.fr.log.FineLoggerFactory; - -import javax.swing.JTree; -import javax.swing.SwingWorker; -import javax.swing.tree.TreeCellRenderer; -import java.util.concurrent.FutureTask; - -/** - * 模糊搜索前需执行完前置任务的TreeComboBox - * @author Lucian.Chen - * @version 10.0 - * Created by Lucian.Chen on 2021/4/14 - */ -public class SearchPreTaskTreeComboBox extends FRTreeComboBox { - - /** - * 模糊搜索前任务 - */ - private FutureTask preSearchTask; - - public SearchPreTaskTreeComboBox(JTree tree, TreeCellRenderer renderer, boolean editable) { - super(tree, renderer, editable); - } - - public FutureTask getPreSearchTask() { - return preSearchTask; - } - - public void setPreSearchTask(FutureTask preSearchTask) { - this.preSearchTask = preSearchTask; - } - - protected UIComboBoxEditor createEditor() { - return new SearchPreTaskComboBoxEditor(this); - } - - private class SearchPreTaskComboBoxEditor extends FrTreeSearchComboBoxEditor { - - public SearchPreTaskComboBoxEditor(FRTreeComboBox comboBox) { - super(comboBox); - } - - protected void changeHandler() { - if (isSetting()) { - return; - } - setPopupVisible(true); - new SwingWorker() { - @Override - protected Void doInBackground() { - FutureTask task = getPreSearchTask(); - try { - // 确保模糊搜索前任务执行完成后,再进行模糊搜索 - if (task != null) { - task.get(); - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - if (task != null) { - // 任务执行后置空,否则会被别的操作重复触发 - setPreSearchTask(null); - } - return null; - } - - @Override - protected void done() { - // 模糊搜索 - search(); - } - }.execute(); - } - } -} diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java new file mode 100644 index 000000000..6b4198693 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/TableSearchTreeComboBox.java @@ -0,0 +1,217 @@ +package com.fr.design.gui.icombobox; + +import com.fr.data.core.DataCoreUtils; +import com.fr.data.core.db.TableProcedure; +import com.fr.data.impl.Connection; +import com.fr.design.DesignerEnvManager; +import com.fr.design.data.datapane.ChoosePane; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.mainframe.DesignerContext; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Filter; +import com.fr.stable.StringUtils; + +import javax.swing.JOptionPane; +import javax.swing.JTree; +import javax.swing.SwingWorker; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeCellRenderer; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import java.awt.event.MouseEvent; +import java.util.Enumeration; + +/** + * 实现模糊搜索表名的FRTreeComboBox + * FRTreeComboBox:搜索后滚动到首个匹配节点 + * SearchFRTreeComboBox:显示所有匹配的节点 + * + * @author Lucian.Chen + * @version 10.0 + * Created by Lucian.Chen on 2021/4/14 + */ +public class TableSearchTreeComboBox extends FRTreeComboBox { + // 持有父容器,需要实时获取其他组件值 + private final ChoosePane parent; + + public TableSearchTreeComboBox(ChoosePane parent, JTree tree, TreeCellRenderer renderer) { + super(tree, renderer); + this.parent = parent; + setUI(new TableSearchTreeComboBoxUI()); + } + + protected UIComboBoxEditor createEditor() { + return new TableSearchComboBoxEditor(this); + } + + @Override + protected String pathToString(TreePath path) { + Object obj = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); + if (obj instanceof TableProcedure) { + return ((TableProcedure) obj).getName(); + } + return super.pathToString(path); + } + + @Override + public void setSelectedItemString(String _name) { + super.setSelectedItemString(_name); + // 会因为连续两次选中的值一致,导致未触发编辑框联动 + this.getEditor().setItem(_name); + } + + /** + * 执行模糊搜索 + */ + private void searchExecute() { + UIComboBoxEditor searchEditor = (UIComboBoxEditor) this.getEditor(); + new SwingWorker() { + @Override + protected Void doInBackground() { + processTableDataNames( + parent.getDSName(), + parent.getConnection(), + parent.getSchema(), + createFilter((String) searchEditor.getItem())); + return null; + } + + @Override + protected void done() { + expandTree(); + // 输入框获取焦点 + searchEditor.getEditorComponent().requestFocus(); + } + }.execute(); + } + + private TableNameFilter createFilter(String text) { + return StringUtils.isEmpty(text) ? EMPTY_FILTER : new TableNameFilter(text); + } + + /** + * 查询数据库表,并构建节点目录 + * + * @param databaseName 数据库名 + * @param connection 数据连接 + * @param schema 模式 + * @param filter 模糊搜索过滤器 + */ + private void processTableDataNames(String databaseName, Connection connection, String schema, TableNameFilter filter) { + if (tree == null) { + return; + } + DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); + rootTreeNode.removeAllChildren(); + + if (connection == null) { + return; + } + try { + schema = StringUtils.isEmpty(schema) ? null : schema; + TableProcedure[] sqlTableArray = DataCoreUtils.getTables(connection, TableProcedure.TABLE, schema, DesignerEnvManager.getEnvManager().isOracleSystemSpace()); + if (ArrayUtils.isNotEmpty(sqlTableArray)) { + ExpandMutableTreeNode tableTreeNode = new ExpandMutableTreeNode(databaseName + "-" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_SQL_Table")); + rootTreeNode.add(tableTreeNode); + addArrayNode(tableTreeNode, sqlTableArray, filter); + } + TableProcedure[] sqlViewArray = DataCoreUtils.getTables(connection, TableProcedure.VIEW, schema, DesignerEnvManager.getEnvManager().isOracleSystemSpace()); + if (ArrayUtils.isNotEmpty(sqlViewArray)) { + ExpandMutableTreeNode viewTreeNode = new ExpandMutableTreeNode(databaseName + "-" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_SQL_View")); + rootTreeNode.add(viewTreeNode); + addArrayNode(viewTreeNode, sqlViewArray, filter); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed"), + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Failed"), JOptionPane.ERROR_MESSAGE); + } + } + + private void addArrayNode(ExpandMutableTreeNode rootNode, TableProcedure[] sqlArray, TableNameFilter filter) { + if (sqlArray != null) { + for (TableProcedure procedure : sqlArray) { + if (filter.accept(procedure)) { + ExpandMutableTreeNode viewChildTreeNode = new ExpandMutableTreeNode(procedure); + rootNode.add(viewChildTreeNode); + } + } + } + } + + /** + * 展开节点 + */ + private void expandTree() { + ((DefaultTreeModel) tree.getModel()).reload(); + // daniel 展开所有tree + TreeNode root = (TreeNode) tree.getModel().getRoot(); + TreePath parent = new TreePath(root); + TreeNode node = (TreeNode) parent.getLastPathComponent(); + for (Enumeration e = node.children(); e.hasMoreElements(); ) { + TreeNode n = (TreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + tree.expandPath(path); + } + } + + private static final TableNameFilter EMPTY_FILTER = new TableNameFilter() { + public boolean accept(TableProcedure procedure) { + return true; + } + }; + + /** + * 表名模糊搜索实现 + */ + private static class TableNameFilter implements Filter { + private String searchFilter; + + public TableNameFilter() { + } + + public TableNameFilter(String searchFilter) { + this.searchFilter = searchFilter.toLowerCase().trim(); + } + + // 表名匹配 + @Override + public boolean accept(TableProcedure procedure) { + return procedure.getName().toLowerCase().contains(searchFilter); + } + } + + /** + * 重写FRTreeComboBoxUI,实现点击下拉时触发模糊搜索 + */ + private class TableSearchTreeComboBoxUI extends FRTreeComboBoxUI { + + @Override + public void mouseClicked(MouseEvent e) { + searchExecute(); + } + } + + /** + * 重写输入框编辑器,实现输入框模糊搜索逻辑 + */ + private class TableSearchComboBoxEditor extends FrTreeSearchComboBoxEditor { + + public TableSearchComboBoxEditor(FRTreeComboBox comboBox) { + super(comboBox); + } + + @Override + protected void changeHandler() { + if (isSetting()) { + return; + } + setPopupVisible(true); + this.item = textField.getText(); + searchExecute(); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIAutoCompletionField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIAutoCompletionField.java index 967aeddbb..f976f3471 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIAutoCompletionField.java +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIAutoCompletionField.java @@ -256,10 +256,9 @@ public class UIAutoCompletionField extends UITextField implements DocumentListen * */ public void setText(String t) { - if (this.isOpen == true) { - if (!UIAutoCompletionField.this.isShowing()) { - return; - } + boolean unavailable = !this.isEnabled() && !this.isEditable(); + if (unavailable) { + return; } try { Document doc = getDocument(); diff --git a/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java b/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java index 2e04b6ce5..dcead1c87 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java @@ -17,14 +17,21 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.NewColorSelectBox; - +import com.fr.general.IOUtils; +import com.fr.design.utils.gui.AdjustWorkBookDefaultStyleUtils; import com.fr.stable.Constants; import com.fr.stable.CoreConstants; -import javax.swing.*; +import javax.swing.Icon; +import javax.swing.JPanel; +import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridLayout; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -38,7 +45,6 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse private static final String[] BORDERARRAY = {"currentLineCombo", "currentLineColorPane", "outerToggleButton", "topToggleButton", "leftToggleButton", "bottomToggleButton", "rightToggleButton", "innerToggleButton", "horizontalToggleButton", "verticalToggleButton"}; private static final Set BORDER_SET = new HashSet<>(Arrays.asList(BORDERARRAY)); - private boolean insideMode = false; private UIToggleButton topToggleButton; private UIToggleButton horizontalToggleButton; @@ -50,11 +56,8 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse private UIToggleButton innerToggleButton; private UIToggleButton outerToggleButton; - private LineComboBox currentLineCombo; - private NewColorSelectBox currentLineColorPane; - private JPanel panel; - private JPanel borderPanel; - private JPanel backgroundPanel; + protected LineComboBox currentLineCombo; + protected NewColorSelectBox currentLineColorPane; private BackgroundPane backgroundPane; private GlobalNameListener globalNameListener = null; @@ -81,18 +84,18 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse new Component[]{null, null}, new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Color") + " ", SwingConstants.LEFT), currentLineColorPane}, new Component[]{null, null}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Out_Border") + " ", SwingConstants.LEFT), outerToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("com/fr/design/images/m_format/out.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/out_white.png")}, false)}, + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Out_Border") + " ", SwingConstants.LEFT), outerToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("com/fr/design/images/m_format/out.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/out_white.png")}, false)}, new Component[]{null, externalPane}, new Component[]{null, null}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_In_Border") + " ", SwingConstants.LEFT), innerToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("com/fr/design/images/m_format/in.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/in_white.png")}, false)}, + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_In_Border") + " ", SwingConstants.LEFT), innerToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("com/fr/design/images/m_format/in.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/in_white.png")}, false)}, new Component[]{null, insidePane}, new Component[]{null, null} }; double[] rowSize = {p, p, p, p, p, p, p, p, p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; - panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_SMALL, LayoutConstants.VGAP_MEDIUM); - borderPanel = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Border"), 280, 24, panel); + JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_SMALL, LayoutConstants.VGAP_MEDIUM); + JPanel borderPanel = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Border"), 280, 24, panel); this.add(borderPanel, BorderLayout.NORTH); UILabel backgroundFillLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Background_Fill")); @@ -102,7 +105,7 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse JPanel backgroundContainPane = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{backgroundFillLabel, backgroundPane}}, TableLayoutHelper.FILL_LASTCOLUMN, LayoutConstants.VGAP_SMALL, LayoutConstants.VGAP_MEDIUM); - backgroundPanel = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background"), 280, 24, backgroundContainPane); + JPanel backgroundPanel = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background"), 280, 24, backgroundContainPane); this.add(backgroundPanel, BorderLayout.CENTER); initAllNames(); outerToggleButton.addChangeListener(outerToggleButtonChangeListener); @@ -130,12 +133,12 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse }; private void initButtonsWithIcon() { - topToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/top.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/top_white.png")}, false); - leftToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/left.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/left_white.png")}, false); - bottomToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/bottom.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bottom_white.png")}, false); - rightToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/right.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/right_white.png")}, false); - horizontalToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/horizontal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/horizontal_white.png")}, false); - verticalToggleButton = new UIToggleButton(new Icon[]{BaseUtils.readIcon("/com/fr/base/images/dialog/border/vertical.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/vertical_white.png")}, false); + topToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/top.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/top_white.png")}, false); + leftToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/left.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/left_white.png")}, false); + bottomToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/bottom.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bottom_white.png")}, false); + rightToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/right.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/right_white.png")}, false); + horizontalToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/horizontal.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/horizontal_white.png")}, false); + verticalToggleButton = new UIToggleButton(new Icon[]{IOUtils.readIcon("/com/fr/base/images/dialog/border/vertical.png"), IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/vertical_white.png")}, false); this.currentLineCombo = new LineComboBox(CoreConstants.UNDERLINE_STYLE_ARRAY); this.currentLineColorPane = new NewColorSelectBox(100); } @@ -174,15 +177,15 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse cellBorderStyle.setRightStyle(style.getBorderRight()); cellBorderStyle.setRightColor(style.getBorderRightColor()); this.backgroundPane.populateBean(style.getBackground()); - this.populateBean(cellBorderStyle, false, style.getBorderTop(), style.getBorderTopColor()); + this.populateBean(cellBorderStyle, false); } - public void populateBean(CellBorderStyle cellBorderStyle, boolean insideMode, int currentStyle, Color currentColor) { - this.insideMode = insideMode; + public void populateBean(CellBorderStyle cellBorderStyle, boolean insideMode) { + populateBean(cellBorderStyle, insideMode, true); + } - this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getTopStyle() == Constants.LINE_NONE ? Constants.LINE_THIN : cellBorderStyle.getTopStyle()); - this.currentLineColorPane.setSelectObject(cellBorderStyle.getTopColor()); + public void populateBean(CellBorderStyle cellBorderStyle, boolean insideMode, boolean onlyInspectTop) { this.topToggleButton.setSelected(cellBorderStyle.getTopStyle() != Constants.LINE_NONE); this.bottomToggleButton.setSelected(cellBorderStyle.getBottomStyle() != Constants.LINE_NONE); @@ -195,16 +198,49 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse this.innerToggleButton.setSelected(cellBorderStyle.getInnerBorder() != Constants.LINE_NONE); this.outerToggleButton.setSelected(cellBorderStyle.getOuterBorderStyle() != Constants.LINE_NONE); - this.innerToggleButton.setEnabled(this.insideMode); - this.horizontalToggleButton.setEnabled(this.insideMode); - this.verticalToggleButton.setEnabled(this.insideMode); + this.innerToggleButton.setEnabled(insideMode); + this.horizontalToggleButton.setEnabled(insideMode); + this.verticalToggleButton.setEnabled(insideMode); + + populateLineStyleAndColor(cellBorderStyle, onlyInspectTop); + } + + public void populateLineStyleAndColor(CellBorderStyle cellBorderStyle, boolean onlyInspectTop) { + if (cellBorderStyle.getTopStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getTopStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getTopColor()); + } else if (!onlyInspectTop) { + if (cellBorderStyle.getBottomStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getBottomStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getBottomColor()); + } else if (cellBorderStyle.getLeftStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getLeftStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getLeftColor()); + } else if (cellBorderStyle.getRightStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getRightStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getRightColor()); + } else if (cellBorderStyle.getVerticalStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getVerticalStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getVerticalColor()); + } else if (cellBorderStyle.getHorizontalStyle() != Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(cellBorderStyle.getHorizontalStyle()); + this.currentLineColorPane.setSelectObject(cellBorderStyle.getHorizontalColor()); + } else { + this.currentLineCombo.setSelectedLineStyle(Constants.LINE_NONE); + this.currentLineColorPane.setSelectObject(Color.BLACK); + } + } + + if (this.currentLineCombo.getSelectedLineStyle() == Constants.LINE_NONE) { + this.currentLineCombo.setSelectedLineStyle(Constants.LINE_THIN); + } } @Override public Style update(Style style) { if (style == null) { - style = Style.DEFAULT_STYLE; + style = AdjustWorkBookDefaultStyleUtils.adjustCellElement(Style.DEFAULT_STYLE); } if (backgroundPane.currentPane.isBackgroundChange()) { @@ -213,7 +249,7 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse if (BORDER_SET.contains(globalNameListener.getGlobalName())) { CellBorderStyle cellBorderStyle = this.update(); style = style.deriveBorder(cellBorderStyle.getTopStyle(), cellBorderStyle.getTopColor(), cellBorderStyle.getBottomStyle(), cellBorderStyle.getBottomColor(), - cellBorderStyle.getLeftStyle(), cellBorderStyle.getLeftColor(), cellBorderStyle.getRightStyle(), cellBorderStyle.getRightColor()); + cellBorderStyle.getLeftStyle(), cellBorderStyle.getLeftColor(), cellBorderStyle.getRightStyle(), cellBorderStyle.getRightColor()); } return style; @@ -253,16 +289,8 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse } cellBorderStyle.setHorizontalStyle(horizontalToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - if (leftToggleButton.isSelected() && bottomToggleButton.isSelected() && rightToggleButton.isSelected() && topToggleButton.isSelected()) { - outerToggleButton.setSelected(true); - } else { - outerToggleButton.setSelected(false); - } - if (verticalToggleButton.isSelected() && horizontalToggleButton.isSelected()) { - innerToggleButton.setSelected(true); - } else { - innerToggleButton.setSelected(false); - } + outerToggleButton.setSelected(leftToggleButton.isSelected() && bottomToggleButton.isSelected() && rightToggleButton.isSelected() && topToggleButton.isSelected()); + innerToggleButton.setSelected(verticalToggleButton.isSelected() && horizontalToggleButton.isSelected()); return cellBorderStyle; } diff --git a/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java index 8c96c4c86..7e0db6051 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java @@ -7,7 +7,6 @@ import com.fr.base.TextFormat; import com.fr.data.core.FormatField; import com.fr.data.core.FormatField.FormatContents; import com.fr.design.border.UIRoundedBorder; -import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; @@ -18,21 +17,18 @@ import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; import com.fr.general.ComparatorUtils; import com.fr.stable.StringUtils; import javax.swing.BorderFactory; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; -import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.TitledBorder; import java.awt.BorderLayout; -import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -43,7 +39,6 @@ import java.awt.event.ItemListener; import java.math.RoundingMode; import java.text.Format; import java.text.SimpleDateFormat; -import java.util.Arrays; /** * @author Starryi @@ -68,69 +63,45 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName private static final Integer[] DATE_TYPES = new Integer[]{FormatContents.NULL, FormatContents.DATE, FormatContents.TIME}; - private Format format; - - private UIComboBox typeComboBox; - private TextFontComboBox textField; - private UILabel sampleLabel; - private JPanel contentPane; - private JPanel txtCenterPane; - private JPanel centerPane; - private JPanel optionPane; - private UICheckBox roundingBox; - private JPanel formatFontPane; + protected UIComboBox typeComboBox; + protected TextFontComboBox textField; + protected UICheckBox roundingBox; + protected UILabel previewLabel; + private boolean isRightFormat; private boolean isDate = false; private GlobalNameListener globalNameListener = null; - /** - * Constructor. - */ public TextFormatPane() { - this.initComponents(TYPES); - } - protected UIComboBox getTypeComboBox() { - return typeComboBox; + initFormatTypesComboBox(); + initTextFontComboBox4GeneralFormats(); + initRoundingCheckBox4PercentFormat(); + initPreviewLabel4GeneralFormat(); + + initLayout(); + + setTextFieldVisible(false); + setRoundingBoxVisible(false); + setPreviewLabelVisible(false); } - protected void initComponents(Integer[] types) { - this.setLayout(new BorderLayout(0, 4)); - initSampleLabel(); - contentPane = new JPanel(new BorderLayout(0, 4)) { - @Override - public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 65); - } - }; - typeComboBox = new UIComboBox(types); - UIComboBoxRenderer render = createComBoxRender(); - typeComboBox.setRenderer(render); + private void initFormatTypesComboBox() { + typeComboBox = new UIComboBox(TextFormatPane.TYPES); + typeComboBox.setRenderer(createComBoxRender()); typeComboBox.addItemListener(itemListener); typeComboBox.setGlobalName("typeComboBox"); - contentPane.add(sampleLabel, BorderLayout.NORTH); + typeComboBox.setPreferredSize(new Dimension(155,20)); + } - txtCenterPane = new JPanel(new BorderLayout()); - textField = new TextFontComboBox(); + private void initTextFontComboBox4GeneralFormats() { + textField = new TextFontComboBox<>(); textField.addItemListener(textFieldItemListener); textField.setEditable(true); textField.setGlobalName("textField"); - txtCenterPane.add(textField, BorderLayout.NORTH); - - contentPane.add(txtCenterPane, BorderLayout.CENTER); - - centerPane = new JPanel(new CardLayout()); - centerPane.add(new JPanel(), "hide"); - centerPane.setPreferredSize(new Dimension(0, 0)); - centerPane.add(contentPane, "show"); - - typeComboBox.setPreferredSize(new Dimension(155,20)); - JPanel typePane = new JPanel(new BorderLayout()); - typePane.add(typeComboBox, BorderLayout.CENTER); - typePane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); + } - JPanel option = new JPanel(new BorderLayout()); - option.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option"), SwingConstants.LEFT), BorderLayout.WEST); + private void initRoundingCheckBox4PercentFormat() { roundingBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Base_Option_Half_Up")); roundingBox.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); roundingBox.addItemListener(new ItemListener() { @@ -139,54 +110,13 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName } }); roundingBox.setGlobalName("roundingBox"); - option.add(roundingBox, BorderLayout.CENTER); - optionPane = new JPanel(new CardLayout()); - optionPane.add(new JPanel(), "hide"); - optionPane.setPreferredSize(new Dimension(0, 0)); - optionPane.add(option, "show"); - - Component[][] components = getComponent(centerPane, typePane); - this.add(createContentPane(components), BorderLayout.CENTER); - } - - protected JPanel createContentPane (Component[][] components) { - double f = TableLayout.FILL; - double p = TableLayout.PREFERRED; - double[] rowSize = new double[components.length]; - Arrays.fill(rowSize, p); - double[] columnSize = {p, f}; - int[][] rowCount = new int[components.length][2]; - Arrays.fill(rowCount, new int[] {1, 1}); - return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); - } - - - protected Component[][] getComponent (JPanel centerPane, JPanel typePane) { - return new Component[][]{ - new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Format"), SwingConstants.LEFT), typePane}, - new Component[]{centerPane, null}, - new Component[]{optionPane, null}, - }; - } - - protected UIComboBoxRenderer createComBoxRender() { - return new UIComboBoxRenderer() { - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Integer) { - label.setText(" " + FormatField.getInstance().getName((Integer) value)); - } - return label; - } - }; } - private void initSampleLabel() { + private void initPreviewLabel4GeneralFormat() { Border interBorder = new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 4); String title = Toolkit.i18nText("Fine-Design_Report_Base_StyleFormat_Sample"); Border border = BorderFactory.createTitledBorder(interBorder, title, TitledBorder.LEFT, 0, null, UIConstants.LINE_COLOR); - sampleLabel = new UILabel(FormatField.getInstance().getFormatValue()) { + previewLabel = new UILabel(FormatField.getInstance().getFormatValue()) { @Override public void paint(Graphics g) { @@ -198,12 +128,65 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName g.setColor(UIConstants.LINE_COLOR); FontMetrics cellFM = g.getFontMetrics(); int textWidth = cellFM.stringWidth(getText()); - GraphHelper.drawString(g, getText(), (width - textWidth) / 2, 26); + GraphHelper.drawString(g, getText(), (width - textWidth) / 2F, 26); g.setColor(original); } }; - sampleLabel.setHorizontalAlignment(UILabel.CENTER); - sampleLabel.setBorder(border); + previewLabel.setHorizontalAlignment(UILabel.CENTER); + previewLabel.setBorder(border); + } + + protected void initLayout() { + JPanel labeledFormatTypeComboBoxPane = new JPanel(new BorderLayout(20, 0)); + labeledFormatTypeComboBoxPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Format")), BorderLayout.WEST); + labeledFormatTypeComboBoxPane.add(typeComboBox, BorderLayout.CENTER); + + JPanel labeledRoundingCheckboxPane = new JPanel(new BorderLayout(0, 0)); + labeledRoundingCheckboxPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option")), BorderLayout.WEST); + labeledRoundingCheckboxPane.add(roundingBox, BorderLayout.CENTER); + + addComponents(4, new JComponent[] { labeledFormatTypeComboBoxPane, textField, labeledRoundingCheckboxPane, previewLabel}); + } + + protected void setTextFieldVisible(boolean visible) { + textField.setVisible(visible); + } + + protected void setRoundingBoxVisible(boolean visible) { + roundingBox.getParent().setVisible(visible); + } + + protected void setPreviewLabelVisible(boolean visible) { + previewLabel.setVisible(visible); + } + + protected void addComponents(int gap, JComponent[] components) { + JPanel container = this; + container.setLayout(new BorderLayout(0, gap)); + for (JComponent component: components) { + if (component != null) { + container.add(component, BorderLayout.NORTH); + JPanel nextContainer = new JPanel(new BorderLayout(0, gap)); + container.add(nextContainer, BorderLayout.CENTER); + container = nextContainer; + } + } + if (container.getComponentCount() == 0) { + container.getParent().remove(container); + } + } + + protected UIComboBoxRenderer createComBoxRender() { + return new UIComboBoxRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof Integer) { + label.setText(" " + FormatField.getInstance().getName((Integer) value)); + } + return label; + } + }; } @@ -231,8 +214,6 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName * Populate */ public void populateBean(Format format) { - this.format = format; - if (format == null) { this.typeComboBox.setSelectedIndex(FormatContents.NULL); } else { @@ -325,17 +306,17 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName * Refresh preview label. */ private void refreshPreviewLabel() { - this.sampleLabel.setText(FormatField.getInstance().getFormatValue()); - this.sampleLabel.setForeground(UIManager.getColor("Label.foreground")); + this.previewLabel.setText(FormatField.getInstance().getFormatValue()); + this.previewLabel.setForeground(UIManager.getColor("Label.foreground")); try { isRightFormat = true; if (StringUtils.isEmpty(String.valueOf(textField.getSelectedItem()))) { return; } - this.sampleLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); + this.previewLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); } catch (Exception e) { - this.sampleLabel.setForeground(Color.red); - this.sampleLabel.setText(e.getMessage()); + this.previewLabel.setForeground(Color.red); + this.previewLabel.setText(e.getMessage()); isRightFormat = false; } } @@ -354,28 +335,16 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { int contents = getFormatContents(); - String[] items = FormatField.getInstance().getFormatArray(contents, false); - CardLayout cardLayout = (CardLayout) centerPane.getLayout(); - if (isTextOrNull()) { - centerPane.setPreferredSize(new Dimension(0, 0)); - cardLayout.show(centerPane, "hide"); - } else { + if (!isTextOrNull()) { textField.removeAllItems(); + String[] items = FormatField.getInstance().getFormatArray(contents, false); textField.setItemArray(items); textField.setSelectedIndex(0); - centerPane.setPreferredSize(new Dimension(270, 65)); - cardLayout.show(centerPane, "show"); - } - CardLayout optionLayout = ((CardLayout) optionPane.getLayout()); - if (getFormatContents() == FormatContents.PERCENT) { - optionPane.setPreferredSize(new Dimension(100, 20)); - optionLayout.show(optionPane, "show"); - } else { - optionPane.setPreferredSize(new Dimension(0, 0)); - optionLayout.show(optionPane, "hide"); - roundingBox.setSelected(false); } + setTextFieldVisible(!isTextOrNull()); + setPreviewLabelVisible(!isTextOrNull()); + setRoundingBoxVisible(getFormatContents() == FormatContents.PERCENT); } } @@ -403,10 +372,20 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName * update */ public Style update(Style style) { - if (ComparatorUtils.equals(globalNameListener.getGlobalName(), "textField") - || ComparatorUtils.equals(globalNameListener.getGlobalName(), "typeComboBox") - || ComparatorUtils.equals(globalNameListener.getGlobalName(), "roundingBox")) { - return style.deriveFormat(this.update()); + return updateByGlobalNamedSetting(style); + } + + private Style updateByGlobalNamedSetting(Style style) { + if (globalNameListener != null) { + String[] alterSettingNames = new String[] {"typeComboBox", "textField", "roundingBox"}; + String globalSettingName = globalNameListener.getGlobalName(); + if (StringUtils.isNotEmpty(globalSettingName)) { + for (String alterSettingName : alterSettingNames) { + if (ComparatorUtils.equals(alterSettingName, globalSettingName)) { + return style.deriveFormat(this.update()); + } + } + } } return style; } diff --git a/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java b/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java new file mode 100644 index 000000000..71c954924 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java @@ -0,0 +1,121 @@ +package com.fr.design.lock; + +import com.fr.design.file.TemplateTreePane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrameFileDealerPane; +import com.fr.design.utils.TemplateUtils; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.file.FileNodeFILE; +import com.fr.file.filetree.FileNode; +import com.fr.general.IOUtils; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; +import com.fr.workspace.base.UserInfo; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JPanel; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/2 + */ +public class LockInfoDialog extends JDialog { + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); + + public LockInfoDialog(UserInfo userInfo) { + super(DesignerContext.getDesignerFrame()); + JPanel panel = new JPanel(new BorderLayout()); + panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + panel.add(createContentPane(userInfo), BorderLayout.CENTER); + panel.add(createControlPane(), BorderLayout.SOUTH); + this.getContentPane().add(panel); + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Title_Hint")); + this.setSize(400, 160); + this.setResizable(false); + this.setModal(true); + GUICoreUtils.centerWindow(this); + this.setVisible(true); + } + + private JPanel createContentPane(UserInfo userInfo) { + JPanel contentPanel = new JPanel(new BorderLayout()); + contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); + JPanel messagePane = new JPanel(new BorderLayout(13, 0)); + UILabel iconLabel = new UILabel(IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png")); + iconLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); + messagePane.add(iconLabel, BorderLayout.WEST); + UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Template_Lock_And_SaveAs_Tip")); + tipLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + messagePane.add(tipLabel, BorderLayout.CENTER); + contentPanel.add(messagePane, BorderLayout.NORTH); + JPanel detailInfoPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + detailInfoPane.setBorder(BorderFactory.createEmptyBorder(0, 45, 0,0)); + if (userInfo != null && StringUtils.isNotEmpty(userInfo.getUserName())) { + UILabel label = createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Holder", userInfo.getUserName())); + label .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + detailInfoPane.add(label); + } + if (userInfo != null && StringUtils.isNotEmpty(userInfo.getIp())) { + detailInfoPane.add(createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Holder_Ip", userInfo.getIp()) )); + } + detailInfoPane.add(createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Get_Time", FORMATTER.format(LocalDateTime.now())))); + contentPanel.add(detailInfoPane, BorderLayout.CENTER); + return contentPanel; + } + + private UILabel createLabel(String text) { + UILabel label = new UILabel(text); + label.setForeground(Color.GRAY); + label.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0)); + return label; + } + + private JPanel createControlPane() { + JPanel controlPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 5)); + controlPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,5)); + UIButton saveAsButton = new UIButton(Toolkit.i18nText("Fine_Design_Template_Lock_Save_As")); + UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")); + saveAsButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + FileNode node = TemplateTreePane.getInstance().getFileNode(); + if (node == null) { + return; + } + final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath()); + TemplateUtils.createAndOpenTemplate(Toolkit.i18nText("Fine_Design_Template_Lock_Copy"), new FileNodeFILE(new FileNode(selectedFilePath, false)), true); + } + }); + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + controlPane.add(saveAsButton); + controlPane.add(cancelButton); + return controlPane; + } + + + public static void show(UserInfo userInfo) { + DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(TemplateTreePane.getInstance().getFileNode()); + new LockInfoDialog(userInfo); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java b/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java new file mode 100644 index 000000000..52a2c526c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java @@ -0,0 +1,23 @@ +package com.fr.design.lock; + +import com.fr.report.lock.DefaultLockInfoOperator; +import com.fr.report.lock.LockInfoOperator; +import com.fr.start.server.FineEmbedServer; +import com.fr.workspace.WorkContext; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/8 + */ +public class LockInfoUtils { + + public static boolean isCompatibleOperator() { + LockInfoOperator lockInfoOperator = WorkContext.getCurrent().get(LockInfoOperator.class); + return lockInfoOperator instanceof DefaultLockInfoOperator; + } + + public static boolean unableGetLockInfo() { + return WorkContext.getCurrent().isLocal() && !FineEmbedServer.isRunning(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 6270413f5..be841f79a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -35,8 +35,11 @@ import com.fr.design.menu.ShortCut; import com.fr.design.os.impl.MacOsAddListenerAction; import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.utils.TemplateUtils; +import com.fr.design.lock.LockInfoDialog; import com.fr.event.EventDispatcher; import com.fr.exception.DecryptTemplateException; +import com.fr.exception.TplLockedException; import com.fr.exit.DesignerExiter; import com.fr.file.FILE; import com.fr.file.FILEFactory; @@ -57,6 +60,7 @@ import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; import com.fr.workspace.connect.WorkspaceConnectionInfo; +import java.util.UUID; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JFrame; @@ -678,7 +682,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta if (!editingTemplate.getEditingFILE().exists()) { path = FILEFactory.MEM_PREFIX + path; } else if (path.startsWith(ProjectConstants.REPORTLETS_NAME)) { - path = workspace.getPath() + File.separator + path; + path = workspace.getPath() + File.separator + TemplateUtils.createLockeTemplatedName(editingTemplate, path); } defaultTitleSB.append(" ").append(path); } @@ -962,6 +966,11 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta } } catch (Throwable t) { FineLoggerFactory.getLogger().error(t.getMessage(), t); + if (t.getCause() instanceof TplLockedException) { + TemplateTreePane.getInstance().getFileNode().setLock(UUID.randomUUID().toString()); + LockInfoDialog.show(null); + return; + } addAndActivateJTemplate(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index a33aa91d5..2b7a321a8 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -43,6 +43,7 @@ import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; +import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; import com.fr.plugin.injectable.PluginModule; @@ -56,6 +57,7 @@ import com.fr.stable.project.ProjectConstants; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; +import com.fr.report.lock.LockInfoOperator; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JOptionPane; @@ -127,6 +129,8 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt private UIToolbar toolBar; + private UIToolbar rightToolBar; + private NewFolderAction newFolderAction = new NewFolderAction(); private RefreshTreeAction refreshTreeAction = new RefreshTreeAction(); @@ -148,7 +152,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt toolBar.setBorderPainted(true); JPanel tooBarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel parent = new JPanel(new BorderLayout()); - parent.add(toolBar, BorderLayout.CENTER); + parent.add(createUpToolBarPane(), BorderLayout.CENTER); parent.setBorder(BorderFactory.createEmptyBorder(3, 0, 4, 0)); tooBarPane.add(parent, BorderLayout.CENTER); tooBarPane.add(new UIMenuHighLight(), BorderLayout.SOUTH); @@ -186,6 +190,56 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt selectedOperation.refresh(); } + private JPanel createUpToolBarPane() { + JPanel panel = new JPanel(new BorderLayout()); + panel.add(toolBar, BorderLayout.CENTER); + if (WorkContext.getCurrent().isRoot()) { + rightToolBar = new UIToolbar(FlowLayout.RIGHT); + rightToolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR)); + rightToolBar.setBorderPainted(true); + UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine_Design_Template_Lock_Status")); + tipLabel.setForeground(Color.GRAY); + rightToolBar.add(tipLabel); + UIButton button = new UIButton(IOUtils.readIcon("/com/fr/design/images/toolbarbtn/lock.png")); + button.setRolloverIcon(IOUtils.readIcon("/com/fr/design/images/toolbarbtn/unlock.png")); + button.setBorderPainted(false); + button.setContentAreaFilled(false); + button.set4ToolbarButton(); + button.setToolTipText(Toolkit.i18nText("Fine_Design_Template_Unlock_Tip")); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine_Design_Template_UnLock_Tip"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE, + IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), + new Object[] {Toolkit.i18nText("Fine_Design_Template_UnLock_I_Known"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); + if (option == JOptionPane.YES_OPTION) { + String path = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getTemplateFileTree().getSelectedTemplatePath()); + boolean success = WorkContext.getCurrent().get(LockInfoOperator.class).unLockTpl(path); + if (success) { + FileNode fileNode = TemplateTreePane.getInstance().getFileNode(); + refreshRightToolBarBy(fileNode); + } else { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Template_Unlock_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + JOptionPane.WARNING_MESSAGE); + FineLoggerFactory.getLogger().error("Unlock {} failed", path); + } + TemplateTreePane.getInstance().refresh(); + } + } + }); + rightToolBar.add(button); + refreshRightToolBarBy(TemplateTreePane.getInstance().getFileNode()); + panel.add(rightToolBar, BorderLayout.EAST); + } + return panel; + } + public final void setCurrentEditingTemplate(JTemplate jt) { DesignModelAdapter.setCurrentModelAdapter(jt.getModel()); @@ -545,6 +599,19 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt } } + public void refreshRightToolBarBy(FileNode fileNode) { + if (rightToolBar != null) { + boolean locked = fileNode != null + && StringUtils.isNotEmpty(fileNode.getLock()) + && !ComparatorUtils.equals(fileNode.getLock(), fileNode.getUserID()); + boolean visible = locked + && WorkContext.getCurrent().isRoot() + && WorkContext.getCurrent().get(LockInfoOperator.class).isUnLockable() + && !WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(fileNode.getEnvPath()); + rightToolBar.setVisible(visible); + } + } + /** * 重命名对话框 * 支持快捷键Enter,ESC diff --git a/designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java similarity index 65% rename from designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java rename to designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java index 5e743d383..1e072d956 100644 --- a/designer-form/src/main/java/com/fr/design/fit/DesignerUIModeConfig.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java @@ -1,19 +1,16 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.base.ScreenResolution; import com.fr.design.fun.ReportLengthUNITProvider; import com.fr.design.unit.UnitConvertUtil; import com.fr.general.ComparatorUtils; -import com.fr.general.FRScreen; import com.fr.stable.Constants; -import java.awt.Dimension; - /** * Created by kerry on 2020-06-05 */ public class DesignerUIModeConfig { - private DesignerUIMode mode = DesignerUIMode.NEW_UI_MODE; + private DesignerUIMode mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; private static class DesignerUIModeConfigHolder { private static final DesignerUIModeConfig designerUIModeConfig = new DesignerUIModeConfig(); @@ -33,22 +30,22 @@ public class DesignerUIModeConfig { * * @return boolean */ - public boolean newUIMode() { - return ComparatorUtils.equals(DesignerUIMode.NEW_UI_MODE, mode); + public boolean simulateWebUIMode() { + return ComparatorUtils.equals(DesignerUIMode.SIMULATE_WEB_UI_MODE, mode); } /** * 设置新ui模式 */ - public void setNewUIMode() { - this.mode = DesignerUIMode.NEW_UI_MODE; + public void setSimulateWebUIMode() { + this.mode = DesignerUIMode.SIMULATE_WEB_UI_MODE; } /** * 设置老ui模式 */ - public void setOldUIMode() { - this.mode = DesignerUIMode.OLD_UI_MODE; + public void setAbsoluteMeasureUIMode() { + this.mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; } /** @@ -70,55 +67,38 @@ public class DesignerUIModeConfig { return mode.getScreenResolution(); } - /** - * 根据屏幕尺寸获取设计时的FRScreen - * - * @param screen 屏幕尺寸 - * @return FRScreen - */ - public FRScreen getDesignScreenByDimension(Dimension screen) { - return mode.getDesignScreenByDimension(screen); - } private enum DesignerUIMode { - OLD_UI_MODE { + ABSOLUTE_MEASURE_UI_MODE { @Override protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { return UnitConvertUtil.parseLengthUNIT(unitType); } - @Override - protected FRScreen getDesignScreenByDimension(Dimension screen) { - return FRScreen.getDesignScreenByDimension(screen); - } - @Override protected int getScreenResolution() { return ScreenResolution.getScreenResolution(); } + }, - NEW_UI_MODE { + SIMULATE_WEB_UI_MODE { @Override protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { return new PXReportLengthUNIT(); } - @Override - protected FRScreen getDesignScreenByDimension(Dimension screen) { - return FRScreen.p1440; - } - @Override protected int getScreenResolution() { return Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION; } + }; protected abstract ReportLengthUNITProvider parseLengthUNIT(int unitType); - protected abstract FRScreen getDesignScreenByDimension(Dimension screen); protected abstract int getScreenResolution(); + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java index 42b1a553e..9757b0f0b 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java @@ -32,12 +32,14 @@ public class DesktopCardPane extends BasicPane implements TargetModifiedListener private static final int TRANSPARENT_LAYER = 1; private static final int LOADING_LAYER = 2; private static final int FAILED_LAYER = 3; + private static final int FORBIDDEN_LAYER = 4; private static final long serialVersionUID = 1L; private JTemplate component; private TransparentPane transparentPane = new TransparentPane(); private JPanel loadingPane = LoadingUtils.createLoadingPane(); private OpenFailedPane failedPane = new OpenFailedPane(); + private ForbiddenPane forbiddenPane = new ForbiddenPane(); Map backUpToolbarComponentState = new HashMap<>(); @@ -54,6 +56,7 @@ public class DesktopCardPane extends BasicPane implements TargetModifiedListener setLayout(new BorderLayout()); layeredPane.add(transparentPane, TRANSPARENT_LAYER); layeredPane.add(failedPane, FAILED_LAYER); + layeredPane.add(forbiddenPane, FORBIDDEN_LAYER); add(layeredPane, BorderLayout.CENTER); } @@ -95,6 +98,8 @@ public class DesktopCardPane extends BasicPane implements TargetModifiedListener showOpenStatus(); } else if (jt.isOpenFailed()) { showOpenFailedCover(jt.getTemplateOpenFailedTip()); + } else if (jt.isForbidden()) { + showForbiddenStatus(); } else { hideCover(); } @@ -140,6 +145,13 @@ public class DesktopCardPane extends BasicPane implements TargetModifiedListener } } + public void showForbiddenStatus() { + component.setVisible(false); + layeredPane.moveToFront(forbiddenPane); + forbidToolBar(); + EastRegionContainerPane.getInstance().updateAllPropertyPane(); + } + public void hideCover() { recoverToolBar(); transparentPane.stop(); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/ForbiddenPane.java b/designer-base/src/main/java/com/fr/design/mainframe/ForbiddenPane.java new file mode 100644 index 000000000..f90391211 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/ForbiddenPane.java @@ -0,0 +1,189 @@ +package com.fr.design.mainframe; + +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.guide.base.GuideView; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.workspace.WorkContext; +import com.fr.report.lock.LockInfoOperator; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.LayoutManager; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingWorker; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/6 + */ +public class ForbiddenPane extends JPanel { + + private static final ImageIcon LOCK_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/mainframe/lock_template.png")); + private static final Color TIP_COLOR = new Color(108, 174, 235); + private static final Color BUTTON_COLOR = new Color(63, 155, 249); + private static final int Y_GAP = 10; + private static final int X_GAP = 10; + private static final int ARC = 4; + + private final UILabel lockLabel; + private final UILabel tipLabel; + private final JButton refreshButton; + + public ForbiddenPane() { + + setLayout(new LayoutManager() { + + @Override + public void removeLayoutComponent(Component comp) { + } + + @Override + public Dimension preferredLayoutSize(Container parent) { + return parent.getPreferredSize(); + } + + @Override + public Dimension minimumLayoutSize(Container parent) { + return null; + } + + @Override + public void layoutContainer(Container parent) { + int width = parent.getParent().getWidth(); + int height = parent.getParent().getHeight(); + int lockLabelWidth = lockLabel.getPreferredSize().width; + int lockLabelHeight = lockLabel.getPreferredSize().height; + int lockLabelX = (width - lockLabelWidth) / 2; + int lockLabelY = (height - lockLabelHeight) / 2; + int tipLabelWidth = tipLabel.getPreferredSize().width; + int tipLabelHeight = tipLabel.getPreferredSize().height; + int tipLabelX = (width - tipLabelWidth) / 2 + X_GAP; + int tipLabelY = lockLabelY + lockLabelHeight; + int refreshButtonWidth = refreshButton.getPreferredSize().width; + int refreshButtonHeight = refreshButton.getPreferredSize().height; + int refreshButtonX = (width - refreshButtonWidth) / 2 + X_GAP; + int refreshButtonY = tipLabelY + refreshButtonHeight + Y_GAP; + lockLabel.setBounds(lockLabelX, lockLabelY, lockLabelWidth, lockLabelHeight); + tipLabel.setBounds(tipLabelX, tipLabelY, tipLabelWidth, tipLabelHeight); + refreshButton.setBounds(refreshButtonX, refreshButtonY, refreshButtonWidth, refreshButtonHeight); + } + + @Override + public void addLayoutComponent(String name, Component comp) { + } + }); + setBackground(Color.WHITE); + lockLabel = new UILabel(LOCK_ICON); + tipLabel = new UILabel(Toolkit.i18nText("Fine_Design_Template_Has_Been_Locked_Tip")); + Font labelFont = tipLabel.getFont(); + tipLabel.setFont(new Font(labelFont.getName(), labelFont.getStyle(), 14)); + tipLabel.setForeground(TIP_COLOR); + refreshButton = new JButton(Toolkit.i18nText("Fine-Design_Basic_Refresh")) { + @Override + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setColor(BUTTON_COLOR); + g2d.fillRoundRect(0, 0, getWidth(), getHeight(), ARC, ARC); + super.paintComponent(g2d); + } + }; + refreshButton.setPreferredSize(new Dimension(68, 24)); + refreshButton.setForeground(Color.WHITE); + refreshButton.setBorderPainted(false); + refreshButton.setContentAreaFilled(false); + refreshButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (template == null) { + return; + } + // 展示下画面 + LoadingDialog loadingDialog = new LoadingDialog(); + loadingDialog.showDialog(); + new SwingWorker(){ + + @Override + protected Boolean doInBackground() throws Exception { + return WorkContext.getCurrent().get(LockInfoOperator.class).isTplLocked(template.getEditingFILE().getPath()); + } + + @Override + protected void done() { + boolean unLocked; + loadingDialog.hideDialog(); + try { + unLocked = !get(); + if (unLocked) { + template.whenClose(); + JTemplate newTemplate = JTemplateFactory.createJTemplate(template.getEditingFILE()); + HistoryTemplateListCache.getInstance().replaceCurrentEditingTemplate(newTemplate); + DesignerContext.getDesignerFrame().addAndActivateJTemplate(newTemplate); + } + } catch (Exception e) { + loadingDialog.hideDialog(); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + }.execute(); + } + }); + add(lockLabel); + add(tipLabel); + add(refreshButton); + } +} + +class LoadingDialog extends JDialog { + + private static final ImageIcon LOADING_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/mainframe/refreh_icon.png")); + + private GuideView guideView; + + public LoadingDialog() { + super(DesignerContext.getDesignerFrame()); + setLayout(new BorderLayout()); + this.getContentPane().setBackground(Color.WHITE); + this.setResizable(false); + this.setUndecorated(true); + this.setAlwaysOnTop(true); + this.setModal(false); + this.setSize(new Dimension(400, 100)); + this.add(new UILabel(LOADING_ICON, UILabel.CENTER), BorderLayout.NORTH); + this.add(new UILabel(Toolkit.i18nText(Toolkit.i18nText("Fine_Design_Template_Refresh")), UILabel.CENTER), BorderLayout.CENTER); + GUICoreUtils.centerWindow(this); + } + + public void showDialog() { + DesignerContext.getDesignerFrame().setExtendedState(JFrame.MAXIMIZED_BOTH); + guideView = new GuideView(DesignerContext.getDesignerFrame()); + GUICoreUtils.centerWindow(DesignerContext.getDesignerFrame(), guideView); + guideView.setBounds(DesignerContext.getDesignerFrame().getBounds()); + guideView.setVisible(true); + this.setVisible(true); + } + + public void hideDialog() { + this.dispose(); + guideView.dismissGuide(); + } + +} 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 4e3c82140..26a2f64bc 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 @@ -58,6 +58,7 @@ import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; import com.fr.design.worker.save.CallbackSaveWorker; import com.fr.design.worker.save.EmptyCallBackSaveWorker; +import com.fr.design.worker.save.SaveFailureHandler; import com.fr.design.write.submit.DBManipulationInWidgetEventPane; import com.fr.design.write.submit.DBManipulationPane; import com.fr.event.EventDispatcher; @@ -83,8 +84,11 @@ import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; import com.fr.plugin.observer.PluginEventType; import com.fr.plugin.observer.PluginListenerRegistration; +import com.fr.report.InconsistentLockException; +import com.fr.report.UnLockedException; import com.fr.report.cell.Elem; import com.fr.report.cell.cellattr.CellImage; +import com.fr.report.lock.LockInfoOperator; import com.fr.stable.ArrayUtils; import com.fr.stable.Filter; import com.fr.stable.ProductConstants; @@ -124,6 +128,8 @@ public abstract class JTemplate> protected U authorityUndoState = null; protected T template; // 当前模板 private boolean isNewCreateTpl = false; //当前模板是否为新建模板 + private volatile boolean forbidden; + /** * 模板过程的相关信息 * @@ -640,6 +646,8 @@ public abstract class JTemplate> */ public void redo() { this.getUndoManager().redo(); + // 重做前模版使用主题可能已经被删除或修改,需要重置模版样式 + checkAndResetTheme(); fireSuperTargetModified(); } @@ -962,7 +970,7 @@ public abstract class JTemplate> export(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE); + SaveFailureHandler.getInstance().process(e); return false; } this.editingFILE = editingFILE; @@ -978,6 +986,14 @@ public abstract class JTemplate> } protected boolean export() throws Exception { + // 保存前校验下未解锁 + if (WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(getEditingFILE().getPath())) { + throw new UnLockedException(); + } + // 校验锁定信息是否一致 + if (getEditingFILE().exists() && !WorkContext.getCurrent().get(LockInfoOperator.class).isConsistentLock(getEditingFILE().getPath())) { + throw new InconsistentLockException(); + } return this.getTarget().export(TemplateResourceManager.getResource().saveTemplate(getEditingFILE())); } @@ -1806,8 +1822,16 @@ public abstract class JTemplate> this.openFailed = openFailed; } + public boolean isForbidden() { + return forbidden; + } + + public void setForbidden(boolean forbidden) { + this.forbidden = forbidden; + } + public boolean checkEnable() { - return !isSaving() && !isOpening() && !isOpenFailed(); + return !isSaving() && !isOpening() && !isOpenFailed() && !isForbidden(); } public String getRuntimeId() { @@ -1840,4 +1864,13 @@ public abstract class JTemplate> templateThemeButton.setText(name); templateThemeButton.setToolTipText(name); } + + public void generateForBiddenTemplate() { + + } + + public void setDesignerUIMode(){ + DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); + } + } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/NorthRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/NorthRegionContainerPane.java index 6802024ea..544dc392a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/NorthRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/NorthRegionContainerPane.java @@ -151,7 +151,7 @@ public class NorthRegionContainerPane extends JPanel { public void execute(Object... objects) { bbsLoginPane[0] = ad.createBBSLoginPane(); } - }, SupportOSImpl.USERINFOPANE); + }, SupportOSImpl. BBS_USER_LOGIN_PANE); processor.hold(northEastPane, LogMessageBar.getInstance(), bbsLoginPane[0]); } northEastPane.add(ad.createAlphaFinePane()); @@ -166,7 +166,7 @@ public class NorthRegionContainerPane extends JPanel { public void execute(Object... objects) { northEastPane.add(ad.createBBSLoginPane()); } - }, SupportOSImpl.USERINFOPANE); + }, SupportOSImpl.BBS_USER_LOGIN_PANE); } diff --git a/designer-form/src/main/java/com/fr/design/fit/PX.java b/designer-base/src/main/java/com/fr/design/mainframe/PX.java similarity index 94% rename from designer-form/src/main/java/com/fr/design/fit/PX.java rename to designer-base/src/main/java/com/fr/design/mainframe/PX.java index 720268ea6..8fd9ac0ed 100644 --- a/designer-form/src/main/java/com/fr/design/fit/PX.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/PX.java @@ -1,4 +1,4 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.stable.Constants; import com.fr.stable.unit.LEN_UNIT; diff --git a/designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java b/designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java similarity index 95% rename from designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java rename to designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java index 8d8f1de16..69d46480e 100644 --- a/designer-form/src/main/java/com/fr/design/fit/PXReportLengthUNIT.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/PXReportLengthUNIT.java @@ -1,4 +1,4 @@ -package com.fr.design.fit; +package com.fr.design.mainframe; import com.fr.design.fun.impl.AbstractReportLengthUNITProvider; import com.fr.stable.unit.UNIT; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java b/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java index 2fbdb974e..9d9eb0058 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java @@ -19,7 +19,17 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane { public ColorBackgroundQuickPane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - colorSelectBox = new NewColorSelectBox(100); + colorSelectBox = new NewColorSelectBox(100) { + @Override + public boolean shouldResponseChangeListener() { + // ColorBackgroundQuickPane注册监听器ChangeListenerImpl的逻辑不能丢,因为里面有修改字段backgroundChange的逻辑. + // 所以在监听器重复注册以及UndoState重复生成时,应该保留ChangeListenerImpl, 而放弃NewColorSelectBox内部自己注册 + // ChangeListener + // REPORT-63760 【主题切换】撤销以后,样式设置有问题 + // REPORT-64006 【模板主题】单元格自定义样式背景色设置不生效 + return false; + } + }; this.add(colorSelectBox, BorderLayout.NORTH); } @@ -40,11 +50,6 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane { return this.colorSelectBox.getSelectObject(); } - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ @Override public void registerChangeListener(final UIObserverListener listener) { this.colorSelectBox.addSelectChangeListener(new ChangeListenerImpl(listener)); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java index 118ea2e32..f965c2172 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java @@ -1,41 +1,41 @@ package com.fr.design.mainframe.loghandler; - -import com.fr.third.apache.log4j.AppenderSkeleton; -import com.fr.third.apache.log4j.Level; -import com.fr.third.apache.log4j.spi.LoggingEvent; - +import com.fr.third.apache.logging.log4j.Level; +import com.fr.third.apache.logging.log4j.core.Filter; +import com.fr.third.apache.logging.log4j.core.Layout; +import com.fr.third.apache.logging.log4j.core.LogEvent; +import com.fr.third.apache.logging.log4j.core.appender.AbstractAppender; +import com.fr.third.apache.logging.log4j.core.config.Property; +import com.fr.third.apache.logging.log4j.core.layout.PatternLayout; +import java.io.Serializable; import java.util.Date; /** * Created by Administrator on 2017/7/18 0018. */ -public class DesignerLogAppender extends AppenderSkeleton { +public class DesignerLogAppender extends AbstractAppender { - public DesignerLogAppender() { - this.layout = new com.fr.third.apache.log4j.PatternLayout("%d{HH:mm:ss} %t %p [%c] %m%n"); + protected DesignerLogAppender(String name, Filter filter, + Layout layout, + boolean ignoreExceptions, + Property[] properties) { + super(name, filter, layout, ignoreExceptions, properties); } - protected void append(LoggingEvent event) { - this.subAppend(event); + public static DesignerLogAppender createDesignerLogAppender() { + return new DesignerLogAppender(DesignerLogAppender.class.getSimpleName(), null, PatternLayout.newBuilder().withPattern("%d{HH:mm:ss} %t %p [%c] %m%n %throwable{0}").build(), false, Property.EMPTY_ARRAY); } - public boolean requiresLayout() { - return true; + @Override + public void append(LogEvent event) { + this.subAppend(event); } - public synchronized void close() { - if (this.closed) { - return; - } - this.closed = true; - - } - public void subAppend(LoggingEvent event) { + public void subAppend(LogEvent event) { synchronized (DesignerLogHandler.getInstance()) { Level level = event.getLevel(); - String msg = this.layout.format(event); + String msg = (String) this.toSerializable(event); DesignerLogHandler.getInstance().printRemoteLog(msg, level, new Date()); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index 1d67c47df..1cb8e5d1a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -9,10 +9,9 @@ import com.fr.general.ComparatorUtils; import com.fr.general.log.Log4jConfig; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; -import com.fr.third.apache.log4j.Level; -import com.fr.third.apache.log4j.spi.LoggingEvent; -import com.fr.third.apache.log4j.spi.ThrowableInformation; +import com.fr.third.apache.logging.log4j.Level; +import com.fr.third.apache.logging.log4j.core.LogEvent; import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.InputMap; @@ -128,7 +127,7 @@ public class DesignerLogHandler { JPopupMenu jPopupMenu = new JPopupMenu(); - int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt(); + int logLevelInt = Log4jConfig.getInstance().getRootLevel().intLevel(); if (logLevelInt <= DesignerLogger.INFO_INT) { jPopupMenu.add(showInfo); jPopupMenu.add(showError); @@ -240,23 +239,22 @@ public class DesignerLogHandler { return resultPane; } - public void printStackTrace(LoggingEvent event) { + public void printStackTrace(LogEvent event) { - int intLevel = event.getLevel().toInt(); - Date date = new Date(event.getTimeStamp()); - ThrowableInformation information = event.getThrowableInformation(); + int intLevel = event.getLevel().intLevel(); + Date date = new Date(event.getTimeMillis()); if (intLevel == DesignerLogger.INFO_INT && showInfo.isSelected()) { - printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable()); + printMessage(event.getMessage().getFormattedMessage(), intLevel, date, event.getThrown()); } else if (intLevel == DesignerLogger.ERROR_INT && showError.isSelected()) { - printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable()); + printMessage(event.getMessage().getFormattedMessage(), intLevel, date, event.getThrown()); } else if (intLevel == DesignerLogger.WARN_INT && showServer.isSelected()) { - printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable()); + printMessage(event.getMessage().getFormattedMessage(), intLevel, date, event.getThrown()); } } public void printStackTrace(String message, Level level, Date date) { - int intLevel = level.toInt(); + int intLevel = level.intLevel(); if (intLevel == DesignerLogger.INFO_INT && showInfo.isSelected()) { printMessage(message, intLevel, date); } else if (intLevel == DesignerLogger.ERROR_INT && showError.isSelected()) { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java index b2b35da1c..3b6d4bf7a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java @@ -1,26 +1,25 @@ package com.fr.design.mainframe.loghandler; import com.fr.log.FineLoggerFactory; -import com.fr.third.apache.log4j.Level; -import com.fr.third.apache.log4j.spi.LoggingEvent; -import com.fr.third.apache.log4j.spi.ThrowableInformation; +import com.fr.third.apache.logging.log4j.Level; +import com.fr.third.apache.logging.log4j.core.LogEvent; /** * 设计器日志记录 */ public class DesignerLogger { - public static final int INFO_INT = Level.INFO.toInt(); + public static final int INFO_INT = Level.INFO.intLevel(); - public static final int ERROR_INT = Level.ERROR.toInt(); + public static final int ERROR_INT = Level.ERROR.intLevel(); - public static final int WARN_INT = Level.WARN.toInt(); + public static final int WARN_INT = Level.WARN.intLevel(); /** * 记录LoggingEvent对象 * * @param event */ - public static void log(LoggingEvent event) { + public static void log(LogEvent event) { if (event == null) { return; } @@ -30,29 +29,27 @@ public class DesignerLogger { public enum LogParser { DEFAULT(-1) { @Override - public void log(LoggingEvent event) { + public void log(LogEvent event) { } }, - INFO(Level.INFO.toInt()) { + INFO(Level.INFO.intLevel()) { @Override - public void log(LoggingEvent event) { - FineLoggerFactory.getLogger().info(event.getRenderedMessage()); + public void log(LogEvent event) { + FineLoggerFactory.getLogger().info(event.getMessage().getFormattedMessage()); } }, - WARN(Level.WARN.toInt()) { + WARN(Level.WARN.intLevel()) { @Override - public void log(LoggingEvent event) { - ThrowableInformation information = event.getThrowableInformation(); - FineLoggerFactory.getLogger().warn(event.getRenderedMessage(), information == null ? null : information.getThrowable()); + public void log(LogEvent event) { + FineLoggerFactory.getLogger().warn(event.getMessage().getFormattedMessage(), event.getThrown()); } }, - ERROR(Level.ERROR.toInt()) { + ERROR(Level.ERROR.intLevel()) { @Override - public void log(LoggingEvent event) { - ThrowableInformation information = event.getThrowableInformation(); - FineLoggerFactory.getLogger().error(event.getRenderedMessage(), information == null ? null : information.getThrowable()); + public void log(LogEvent event) { + FineLoggerFactory.getLogger().error(event.getMessage().getFormattedMessage(), event.getThrown()); } }; private int level; @@ -65,8 +62,8 @@ public class DesignerLogger { return level; } - public static LogParser parse(LoggingEvent event) { - int intLevel = event.getLevel().toInt(); + public static LogParser parse(LogEvent event) { + int intLevel = event.getLevel().intLevel(); for (LogParser logParser : values()) { if (logParser.getLevel() == intLevel) { return logParser; @@ -76,7 +73,7 @@ public class DesignerLogger { } - public void log(LoggingEvent event) { + public void log(LogEvent event) { } } } \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java similarity index 65% rename from designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java rename to designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java index 78369ba13..92e7548b5 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java @@ -1,17 +1,14 @@ -package com.fr.design.mainframe.cell.settingpane.style; +package com.fr.design.mainframe.theme; -import com.fr.base.NameStyle; -import com.fr.base.Style; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedCellStyle; import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.cell.CellStylePreviewPane; +import com.fr.design.cell.CellRectangleStylePreviewPane; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerBean; -import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.general.ComparatorUtils; @@ -30,18 +27,18 @@ import java.awt.Dimension; import java.io.Serializable; import java.util.List; -public class ThemedCellStyleListPane extends FurtherBasicBeanPane implements DesignerBean { +public class ThemedCellStyleListPane extends FurtherBasicBeanPane implements DesignerBean { private static final int LEFT_BORDER = 10; private static final int RIGHT_BORDER = 10; - private final DefaultListModel defaultListModel; - private final JList styleList; + private final DefaultListModel defaultListModel; + private final JList styleList; private ChangeListener changeListener; - public ThemedCellStyleListPane() { + public ThemedCellStyleListPane(boolean supportInnerBorder) { defaultListModel = new DefaultListModel<>(); styleList = new JList<>(defaultListModel); - styleList.setCellRenderer(new RadioButtonListCellRenderer()); + styleList.setCellRenderer(new RadioButtonListCellRangeRenderer(supportInnerBorder)); styleList.setOpaque(false); styleList.setBackground(null); styleList.addListSelectionListener(new ListSelectionListener() { @@ -55,15 +52,8 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp setLayout(FRGUIPaneFactory.createBorderLayout()); add(styleList, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(0 ,LEFT_BORDER, 0, RIGHT_BORDER)); - - DesignerContext.setDesignerBean("predefinedStyle", this); } - /** - * 添加改变监听 - * - * @param changeListener 监听事件 - */ public void addChangeListener(ChangeListener changeListener) { this.changeListener = changeListener; } @@ -77,7 +67,7 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp } @Override - public void populateBean(NameStyle ob) { + public void populateBean(ThemedCellStyle ob) { refreshBeanElement(); if (ob == null) { styleList.setSelectedIndex(0); @@ -92,32 +82,21 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp } @Override - public NameStyle updateBean() { + public ThemedCellStyle updateBean() { return styleList.getSelectedValue(); } - /** - * 获取面板标题 - * - * @return 标题 - */ + @Override public String title4PopupWindow() { return Toolkit.i18nText("Fine-Design_Report_Predefined_Style"); } - /** - * 是否可以接纳对象 - * - * @param ob 组件对象 - * @return 是否可以接纳对象 - */ + @Override public boolean accept(Object ob) { - return ob instanceof NameStyle; + return ob instanceof ThemedCellStyle; } - /** - * 刷新组件对象 - */ + @Override public void refreshBeanElement() { defaultListModel.removeAllElements(); JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); @@ -125,35 +104,39 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp TemplateTheme theme = template.getTemplateTheme(); List styleList = theme.getCellStyleList().getCellStyleList(); for (ThemedCellStyle themedCellStyle: styleList) { - String name = themedCellStyle.getName(); - Style realStyle = themedCellStyle.getStyle(); - NameStyle nameStyle = NameStyle.getPassiveInstance(name, realStyle); - defaultListModel.addElement(nameStyle); + defaultListModel.addElement(themedCellStyle); } } styleList.setModel(defaultListModel); } - private static class RadioButtonListCellRenderer extends JPanel implements ListCellRenderer, Serializable { + private static class RadioButtonListCellRangeRenderer extends JPanel implements ListCellRenderer, Serializable { private final UIRadioButton button; - private final CellStylePreviewPane previewArea; + private final CellRectangleStylePreviewPane previewArea; - public RadioButtonListCellRenderer() { + public RadioButtonListCellRangeRenderer(boolean supportInnerBorder) { super(); - setLayout(new BorderLayout(20, 0)); - setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - setPreferredSize(new Dimension(getPreferredSize().width, 40)); + setLayout(new BorderLayout(5, 0)); + setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); button = new UIRadioButton(); - previewArea = new CellStylePreviewPane(); + button.setBorder(BorderFactory.createEmptyBorder()); + previewArea = new CellRectangleStylePreviewPane(supportInnerBorder); add(button, BorderLayout.WEST); add(previewArea, BorderLayout.CENTER); } @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + public Component getListCellRendererComponent(JList list, ThemedCellStyle value, int index, boolean isSelected, boolean cellHasFocus) { button.setSelected(isSelected); - previewArea.setStyle((Style) value); + previewArea.setPlainText(value.getName()); + previewArea.setStyle(value.getStyle(), value.getCellBorderStyle()); + + int preferredWidth = list.getWidth() - 15 - button.getPreferredSize().width; + preferredWidth = Math.max(0, preferredWidth); + int preferredHeight = 0; + previewArea.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); + return this; } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedFeatureController.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedFeatureController.java new file mode 100644 index 000000000..2e0fc5c38 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedFeatureController.java @@ -0,0 +1,17 @@ +package com.fr.design.mainframe.theme; + +import com.fr.workspace.WorkContext; +import com.fr.workspace.server.theme.SupportThemedCellInnerBorderFeature; +import com.fr.workspace.server.theme.ThemedCellBorderFeature; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/11/26 + */ +public class ThemedFeatureController { + public static boolean isCellStyleSupportInnerBorder() { + ThemedCellBorderFeature controller = WorkContext.getCurrent().get(ThemedCellBorderFeature.class); + return controller instanceof SupportThemedCellInnerBorderFeature; + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeDialog.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeDialog.java index 875cc6bae..1864a91b1 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeDialog.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeDialog.java @@ -28,15 +28,14 @@ public abstract class TemplateThemeDialog extends JDialog { private final JPanel contentContainer; private final JPanel actionContainer; + private final int dialogContentHeight; public TemplateThemeDialog(Window parent, String title, int contentWidth, int contentHeight) { super(parent, ModalityType.APPLICATION_MODAL); - setTitle(title); setResizable(false); setLayout(FRGUIPaneFactory.createBorderLayout()); - - int dialogContentHeight = contentHeight + DIALOG_BOTTOM_ACTION_BAR_HEIGHT; + dialogContentHeight = contentHeight + DIALOG_BOTTOM_ACTION_BAR_HEIGHT; int dialogWindowHeight = dialogContentHeight + DIALOG_TITLE_HEIGHT; setSize(new Dimension(contentWidth, dialogWindowHeight)); @@ -54,6 +53,12 @@ public abstract class TemplateThemeDialog extends JDialog { setContentPane(contentContainer); } + @Override + public void doLayout() { + this.setSize(new Dimension(this.getWidth(), dialogContentHeight + this.getInsets().top)); + super.doLayout(); + } + protected void setupContentPane() { contentContainer.add(createContentPane(), BorderLayout.CENTER, 0); } @@ -63,10 +68,11 @@ public abstract class TemplateThemeDialog extends JDialog { } protected UIButton[] createLeftButtons() { - return new UIButton[] {}; + return new UIButton[]{}; } + protected UIButton[] createRightButtons() { - return new UIButton[] {}; + return new UIButton[]{}; } public void setupActionButtons() { @@ -89,7 +95,7 @@ public abstract class TemplateThemeDialog extends JDialog { } private JPanel createActionsContainer(int align, UIButton... buttons) { - JPanel container = new JPanel(new FlowLayout(align, DIALOG_BOTTOM_ACTION_BUTTON_GAP, 0)); + JPanel container = new JPanel(new FlowLayout(align, DIALOG_BOTTOM_ACTION_BUTTON_GAP, 0)); int paddingVertical = getPaddingVertical(); container.setBorder(BorderFactory.createEmptyBorder(paddingVertical, 0, paddingVertical, 0)); @@ -97,7 +103,7 @@ public abstract class TemplateThemeDialog extends JDialog { return container; } - for (UIButton button: buttons) { + for (UIButton button : buttons) { if (button != null) { button.setPreferredSize(new Dimension(button.getPreferredSize().width, DIALOG_BOTTOM_ACTION_BUTTON_HEIGHT)); container.add(button); @@ -111,7 +117,7 @@ public abstract class TemplateThemeDialog extends JDialog { return createActionsContainer(FlowLayout.RIGHT, buttons); } - private int getPaddingVertical(){ + private int getPaddingVertical() { return (DIALOG_BOTTOM_ACTION_BAR_HEIGHT - DIALOG_BOTTOM_ACTION_BUTTON_HEIGHT) / 2; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/CellStyleListEditPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/CellStyleListEditPane.java index 6b12c37d4..ec0d085b9 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/CellStyleListEditPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/CellStyleListEditPane.java @@ -1,9 +1,7 @@ package com.fr.design.mainframe.theme.edit; -import com.fr.base.Style; import com.fr.base.theme.settings.ThemedCellStyle; import com.fr.base.theme.settings.ThemedCellStyleList; -import com.fr.config.predefined.PredefinedCellStyle; import com.fr.design.actions.UpdateAction; import com.fr.design.beans.BasicBeanPane; import com.fr.design.dialog.FineJOptionPane; @@ -122,7 +120,7 @@ public class CellStyleListEditPane extends JListControlPane { } @Override - public BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { CellStyleEditPane stylePane = (CellStyleEditPane) super.createPaneByCreators(creator); stylePane.registerAttrChangeListener(attributeChangeListener); return stylePane; @@ -256,23 +254,15 @@ public class CellStyleListEditPane extends JListControlPane { this(CellStyleEditPane.class); } - public CellStyleNameObjectCreator(Class updatePane) { + public CellStyleNameObjectCreator(Class> updatePane) { super(i18nText("Fine-Design_Predefined_Cell_New_Style"), ThemedCellStyle.class, updatePane); } @Override public Nameable createNameable(UnrepeatedNameHelper helper) { - ThemedCellStyle cellStyle = new ThemedCellStyle(); + ThemedCellStyle cellStyle = ThemedCellStyle.createInstanceUsed4New(); cellStyle.setName(menuName); - cellStyle.setStyle(Style.getInstance()); - cellStyle.setRemovable(true); - cellStyle.setUse4Default(false); - cellStyle.setUse4BigTitle(false); - cellStyle.setUse4SmallTitle(false); - cellStyle.setUse4Header(false); - cellStyle.setUse4MainText(false); - cellStyle.setUse4SupportInfo(false); - cellStyle.setUse4HighlightText(false); + return new NameObject(helper.createUnrepeatedName(this.menuName()), cellStyle); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java index b2d182422..6c6395350 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java @@ -1,7 +1,9 @@ package com.fr.design.mainframe.theme.edit.cell; +import com.fr.base.CellBorderStyle; +import com.fr.base.Style; import com.fr.base.theme.settings.ThemedCellStyle; -import com.fr.design.cell.CellStylePreviewPane; +import com.fr.design.cell.CellRectangleStylePreviewPane; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.AttrScrollPane; import com.fr.design.dialog.BasicPane; @@ -14,6 +16,7 @@ import com.fr.design.gui.style.AlignmentPane; import com.fr.design.gui.style.BorderPane; import com.fr.design.gui.style.TextFontTippedPane; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.theme.ThemedFeatureController; import com.fr.design.mainframe.theme.ui.BorderUtils; import javax.swing.BorderFactory; @@ -35,7 +38,7 @@ import static com.fr.design.i18n.Toolkit.i18nText; */ public class CellStyleEditPane extends MultiTabPane { private ThemedCellStyle cellStyle; - private CellStylePreviewPane previewArea; + private CellRectangleStylePreviewPane previewArea; private boolean populating; private AttributeChangeListener attributeChangeListener; @@ -74,7 +77,11 @@ public class CellStyleEditPane extends MultiTabPane { for (BasicPane basicPane : paneList) { ((AbstractBasicStylePane) basicPane).populateBean(ob.getStyle()); - previewArea.setStyle(ob.getStyle()); + previewArea.setPlainText(ob.getName()); + previewArea.setStyle(ob.getStyle(), ob.getCellBorderStyle()); + if (ThemedFeatureController.isCellStyleSupportInnerBorder() && basicPane instanceof BorderPane) { + ((BorderPane) basicPane).populateBean(ob.getCellBorderStyle(), true, false); + } } this.populating = false; } @@ -82,9 +89,35 @@ public class CellStyleEditPane extends MultiTabPane { @Override public ThemedCellStyle updateBean() { AbstractBasicStylePane basicStylePane = (AbstractBasicStylePane) paneList.get(tabPane.getSelectedIndex()); - this.cellStyle.setStyle(basicStylePane.update(this.cellStyle.getStyle())); + Style style = basicStylePane.update(this.cellStyle.getStyle()); + CellBorderStyle borderStyle = createDefaultBorderStyleFromStyle(style); + + + if (ThemedFeatureController.isCellStyleSupportInnerBorder() && basicStylePane instanceof BorderPane) { + borderStyle = ((BorderPane) basicStylePane).update(); + } + + this.cellStyle.setStyle(style); + this.cellStyle.setCellBorderStyle(borderStyle); + return this.cellStyle; } + private CellBorderStyle createDefaultBorderStyleFromStyle(Style style) { + CellBorderStyle cellBorderStyle = new CellBorderStyle(); + cellBorderStyle.setTopStyle(style.getBorderTop()); + cellBorderStyle.setTopColor(style.getBorderTopColor()); + + cellBorderStyle.setBottomStyle(style.getBorderBottom()); + cellBorderStyle.setBottomColor(style.getBorderBottomColor()); + + cellBorderStyle.setLeftStyle(style.getBorderLeft()); + cellBorderStyle.setLeftColor(style.getBorderLeftColor()); + + cellBorderStyle.setRightStyle(style.getBorderRight()); + cellBorderStyle.setRightColor(style.getBorderRightColor()); + + return cellBorderStyle; + } @Override public boolean accept(Object ob) { @@ -102,16 +135,18 @@ public class CellStyleEditPane extends MultiTabPane { @Override protected void initLayout() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setLayout(new BorderLayout(0, 10)); JPanel jPanel = new JPanel(); jPanel.setLayout(new BorderLayout(0, 4)); JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - previewArea = new CellStylePreviewPane(); - previewArea.setPreferredSize(new Dimension(223, 30)); - previewPane.setBorder(BorderUtils.createTitleBorder(i18nText("Fine-Design_Basic_Preview"))); - previewPane.add(previewArea, BorderLayout.CENTER); + previewArea = new CellRectangleStylePreviewPane(true); + previewArea.setPreferredSize(new Dimension(215, 48)); + previewPane.setBorder(BorderFactory.createCompoundBorder( + BorderUtils.createTitleBorder(i18nText("Fine-Design_Basic_Preview")), + BorderFactory.createEmptyBorder(4, 4, 4, 4))); + previewPane.add(previewArea, BorderLayout.NORTH); this.add(previewPane, BorderLayout.NORTH); @@ -135,7 +170,8 @@ public class CellStyleEditPane extends MultiTabPane { } ThemedCellStyle cellStyle = updateBean(); if (cellStyle != null) { - previewArea.setStyle(cellStyle.getStyle()); + previewArea.setPlainText(cellStyle.getName()); + previewArea.setStyle(cellStyle.getStyle(), cellStyle.getCellBorderStyle()); } fireAttrChangeListener(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java index ee04556c6..84a615f61 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java @@ -7,6 +7,7 @@ import com.fr.design.constants.LayoutConstants; import com.fr.design.dialog.BasicPane; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIColorButton; +import com.fr.design.gui.ibutton.UIColorButtonWithAuto; import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; @@ -56,7 +57,7 @@ public class ChartFontPane extends BasicPane { fontSizeComboBox = new UIComboBox(FONT_SIZES); bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); - fontColor = new UIColorButton(); + fontColor = new UIColorButtonWithAuto(); } protected void initComponents() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListPane.java index 5c282033f..ab5d8a4ec 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListPane.java @@ -139,7 +139,7 @@ public class ColorListPane extends JPanel implements UIObserver { return true; } - private static class ColorButton extends AbstractSelectBox { + public static class ColorButton extends AbstractSelectBox { private Color color; private NewColorSelectPane colorPane; private ChangeListener changeListener; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java index 2033e7072..103b6ca6e 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java @@ -45,8 +45,9 @@ public class ReportThemePreviewPane extends TemplateThemePreviewPane { - protected Style getReportBigTitleStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4BigTitle()); - } - protected Style getReportHeaderStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4Header()); - } - - protected Style getMainContentStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4MainText()); - } - - protected Style getHighLightStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4HighlightText()); - } - - protected Style getSmallTitleStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4SmallTitle()); - } - - protected Style getAssistMsgStyle(ThemedCellStyleList cellStyleList) { - return getCellStyle(cellStyleList.getUse4SupportInfo()); - } - private Style getCellStyle(ThemedCellStyle themedCellStyle) { if (themedCellStyle == null) { return Style.DEFAULT_STYLE; @@ -42,9 +20,19 @@ public abstract class AbstractECPreviewPane extends UINoOpaquePanel implements T return style != null ? style : Style.DEFAULT_STYLE; } - protected void refresh(List list, Style style) { + private CellBorderStyle getCellBorderStyle(ThemedCellStyle themedCellStyle) { + if (themedCellStyle == null) { + return null; + } + return themedCellStyle.getCellBorderStyle(); + } + + protected void refresh(List list, ThemedCellStyle themedCellStyle) { + Style style = getCellStyle(themedCellStyle); + CellBorderStyle borderStyle = getCellBorderStyle(themedCellStyle); + for (AbstractPreviewCell cell : list) { - cell.refresh(style); + cell.refresh(style, borderStyle); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java index aeb4fbef2..2ac59af94 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.theme.preview.ecpreview; +import com.fr.base.CellBorderSourceFlag; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedCellStyleList; import com.fr.design.i18n.Toolkit; @@ -36,8 +37,16 @@ public class ECPreviewPane extends AbstractECPreviewPane { JPanel extCenterPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); this.add(extCenterPane, BorderLayout.CENTER); extCenterPane.add(titlePane, BorderLayout.NORTH); - for (int i = 0; i < COL_COUNT; i++) { + for (int c = 0; c < COL_COUNT; c++) { PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); cell.setPreferredSize(new Dimension(103, 36)); titlePane.add(cell); headerCellList.add(cell); @@ -46,6 +55,22 @@ public class ECPreviewPane extends AbstractECPreviewPane { extCenterPane.add(contentPane, BorderLayout.CENTER); for (int i = 0; i < COL_COUNT * CONTENT_ROW_COUNT; i++) { PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text")); + int r = i / COL_COUNT; + int c = i % COL_COUNT; + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r > 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r < CONTENT_ROW_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); cell.setPreferredSize(new Dimension(103, 30)); contentPane.add(cell); contentCellList.add(cell); @@ -53,8 +78,16 @@ public class ECPreviewPane extends AbstractECPreviewPane { JPanel endPane = new UINoOpaquePanel(new GridLayout()); extCenterPane.add(endPane, BorderLayout.SOUTH); - for (int i = 0; i < COL_COUNT; i++) { + for (int c = 0; c < COL_COUNT; c++) { PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); cell.setPreferredSize(new Dimension(103, 30)); endPane.add(cell); highLightCellList.add(cell); @@ -62,6 +95,7 @@ public class ECPreviewPane extends AbstractECPreviewPane { JPanel extSouthPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); PreviewCell assistCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Assist_Text")); + assistCell.setBorderSourceFlag(CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER); assistCell.setPreferredSize(new Dimension(123, 30)); assistCellList.add(assistCell); extSouthPane.add(assistCell); @@ -71,11 +105,10 @@ public class ECPreviewPane extends AbstractECPreviewPane { @Override public void refresh(TemplateTheme theme) { ThemedCellStyleList cellStyleConfig = theme.getCellStyleList(); - refresh(headerCellList, getReportHeaderStyle(cellStyleConfig)); - refresh(contentCellList, getMainContentStyle(cellStyleConfig)); - refresh(highLightCellList, getHighLightStyle(cellStyleConfig)); - refresh(highLightCellList, getHighLightStyle(cellStyleConfig)); - refresh(assistCellList, getAssistMsgStyle(cellStyleConfig)); + refresh(headerCellList, cellStyleConfig.getUse4Header()); + refresh(contentCellList, cellStyleConfig.getUse4MainText()); + refresh(highLightCellList, cellStyleConfig.getUse4HighlightText()); + refresh(assistCellList, cellStyleConfig.getUse4SupportInfo()); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java index 432c8b49c..98f75538f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.theme.preview.ecpreview; +import com.fr.base.CellBorderSourceFlag; import com.fr.base.theme.ReportTheme; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedCellStyleList; @@ -22,12 +23,12 @@ import java.util.ArrayList; import java.util.List; public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreviewed { - private final List headerTitleCellList = new ArrayList<>(); - private final List headerCellList = new ArrayList<>(); - private final List titleCellList = new ArrayList<>(); - private final List contentCellList = new ArrayList<>(); - private final List highLightCellList = new ArrayList<>(); - private final List assistCellList = new ArrayList<>(); + private final List headerTitleCellList = new ArrayList<>(); // 大标题样式单元格 + private final List headerCellList = new ArrayList<>(); // 表头样式单元格 + private final List titleCellList = new ArrayList<>(); // 小标题样式单元格 + private final List contentCellList = new ArrayList<>(); // 正文样式单元格 + private final List highLightCellList = new ArrayList<>(); // 高亮文本样式单元格 + private final List assistCellList = new ArrayList<>(); // 辅助信息样式单元格 private static final int CONTENT_ROW_COUNT = 3; private static final int COL_COUNT = 5; @@ -64,31 +65,38 @@ public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreview private JPanel createNorthPane() { JPanel northPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); AbstractPreviewCell bigTitleCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Cell_Style_Big_Title")); + bigTitleCell.setBorderSourceFlag(CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER); bigTitleCell.setPreferredSize(new Dimension(615, 46)); headerTitleCellList.add(bigTitleCell); northPane.add(bigTitleCell, BorderLayout.NORTH); CornerPreviewCell cornerCell = new CornerPreviewCell(new String[]{Toolkit.i18nText("Fine-Design_Basic_Column_Name"), Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_EC_Data"), Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Row_Name")}, new Point2D[]{new Point(159, 71), new Point(225, 49)}); + cornerCell.setBorderSourceFlag(CellBorderSourceFlag.INVALID_BORDER_SOURCE); cornerCell.setPreferredSize(new Dimension(225, 71)); titleCellList.add(cornerCell); northPane.add(cornerCell, BorderLayout.WEST); JPanel centerPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); northPane.add(centerPane, BorderLayout.CENTER); PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Small_Title")); + cell.setBorderSourceFlag(CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER); titleCellList.add(cell); cell.setPreferredSize(new Dimension(308, 38)); centerPane.add(cell, BorderLayout.NORTH); JPanel eastSouthPane = new UINoOpaquePanel(new GridLayout()); - PreviewCell cell1 = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); - PreviewCell cell2 = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); - PreviewCell cell3 = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); - headerCellList.add(cell1); - headerCellList.add(cell2); - headerCellList.add(cell3); - eastSouthPane.add(cell1); - eastSouthPane.add(cell2); - eastSouthPane.add(cell3); + for (int c = 0; c < CONTENT_ROW_COUNT; c++) { + PreviewCell headerCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < CONTENT_ROW_COUNT - 1) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + headerCell.setBorderSourceFlag(flag); + headerCellList.add(headerCell); + eastSouthPane.add(headerCell); + } centerPane.add(eastSouthPane, BorderLayout.CENTER); return northPane; } @@ -102,8 +110,16 @@ public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreview cell1.setPreferredSize(new Dimension(112, 153)); westPane.add(cell1, BorderLayout.WEST); JPanel gridPane = new UINoOpaquePanel(new GridLayout(5, 1)); - for (int i = 0; i < COL_COUNT; i++) { + for (int r = 0; r < COL_COUNT; r++) { PreviewCell cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r > 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); cell.setPreferredSize(new Dimension(113, 31)); headerCellList.add(cell); gridPane.add(cell); @@ -114,11 +130,36 @@ public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreview centerPane.add(innerCenterPane, BorderLayout.CENTER); for (int i = 0; i < COL_COUNT * CONTENT_ROW_COUNT; i++) { PreviewCell cell ; - if ((i + 1) % CONTENT_ROW_COUNT == 0) { + int r = i / CONTENT_ROW_COUNT; + int c = i % CONTENT_ROW_COUNT; + if (c == CONTENT_ROW_COUNT - 1) { cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r != 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r != COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); highLightCellList.add(cell); } else { cell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text")); + int flag = CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER; + if (r > 0) { + flag |= CellBorderSourceFlag.TOP_BORDER_SOURCE_INNER; + } + if (r < COL_COUNT - 1) { + flag |= CellBorderSourceFlag.BOTTOM_BORDER_SOURCE_INNER; + } + if (c > 0) { + flag |= CellBorderSourceFlag.LEFT_BORDER_SOURCE_INNER; + } + if (c < CONTENT_ROW_COUNT - 2) { + flag |= CellBorderSourceFlag.RIGHT_BORDER_SOURCE_INNER; + } + cell.setBorderSourceFlag(flag); + contentCellList.add(cell); } cell.setPreferredSize(new Dimension(123, 31)); @@ -132,6 +173,7 @@ public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreview private JPanel createSouthPane(){ JPanel southPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); PreviewCell assistCell = new PreviewCell(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Assist_Text")); + assistCell.setBorderSourceFlag(CellBorderSourceFlag.ALL_BORDER_SOURCE_OUTER); assistCell.setPreferredSize(new Dimension(123, 30)); assistCellList.add(assistCell); southPane.add(assistCell, BorderLayout.CENTER); @@ -141,12 +183,12 @@ public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreview @Override public void refresh(TemplateTheme theme) { ThemedCellStyleList cellStyleConfig = theme.getCellStyleList(); - refresh(headerTitleCellList, getReportBigTitleStyle(cellStyleConfig)); - refresh(headerCellList, getReportHeaderStyle(cellStyleConfig)); - refresh(contentCellList, getMainContentStyle(cellStyleConfig)); - refresh(titleCellList, getSmallTitleStyle(cellStyleConfig)); - refresh(highLightCellList, getHighLightStyle(cellStyleConfig)); - refresh(assistCellList, getAssistMsgStyle(cellStyleConfig)); + refresh(headerTitleCellList, cellStyleConfig.getUse4BigTitle()); + refresh(headerCellList, cellStyleConfig.getUse4Header()); + refresh(contentCellList, cellStyleConfig.getUse4MainText()); + refresh(titleCellList, cellStyleConfig.getUse4SmallTitle()); + refresh(highLightCellList, cellStyleConfig.getUse4HighlightText()); + refresh(assistCellList, cellStyleConfig.getUse4SupportInfo()); } } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java index a8a5f1892..fdd4dd3ca 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java @@ -1,25 +1,46 @@ package com.fr.design.mainframe.theme.preview.ecpreview.cell; +import com.fr.base.CellBorderSourceFlag; +import com.fr.base.CellBorderStyle; import com.fr.base.Style; +import com.fr.stable.Constants; + import javax.swing.JComponent; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; public abstract class AbstractPreviewCell extends JComponent { + private static final double BORDER_INSET = 0.5D; protected Style style = Style.DEFAULT_STYLE; private static final int NO_SCALE_RESOLUTION = 100; + private int borderSourceFlag = CellBorderSourceFlag.INVALID_BORDER_SOURCE; + public void setBorderSourceFlag(int borderSourceFlag) { + this.borderSourceFlag = borderSourceFlag; + } - public void refresh(Style style) { - this.style = style; + public void refresh(Style style, CellBorderStyle borderStyle) { + this.style = CellBorderSourceFlag.deriveBorderedStyle(style, borderStyle, borderSourceFlag); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Style.paintBackground(g2d, style, getWidth(), getHeight()); paintContent(g2d, NO_SCALE_RESOLUTION); - Style.paintBorder(g2d, style, getWidth(), getHeight()); + paintBorder(g2d); + } + + private void paintBorder(Graphics2D g2d) { + double width = getWidth(); + double height = getHeight(); + if (style.getBorderLeft() == Constants.LINE_SLIM || style.getBorderRight() == Constants.LINE_SLIM) { + width -= BORDER_INSET; + } + if (style.getBorderBottom() == Constants.LINE_SLIM || style.getBorderTop() == Constants.LINE_SLIM) { + height -= BORDER_INSET; + } + Style.paintBorder(g2d, style, width, height); } protected abstract void paintContent(Graphics2D g2d, int resolution); diff --git a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java index 949d77045..e8871154e 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java @@ -1,6 +1,7 @@ package com.fr.design.os.impl; import com.fr.base.FRContext; +import com.fr.design.config.DesignerProperties; import com.fr.design.jdk.JdkVersion; import com.fr.general.CloudCenter; import com.fr.general.GeneralContext; @@ -22,11 +23,11 @@ import java.util.Locale; public enum SupportOSImpl implements SupportOS { /** - * ARM下屏蔽登录 + * 屏蔽登录入口 */ - USERINFOPANE{ + BBS_USER_LOGIN_PANE { public boolean support(){ - return Arch.getArch() != Arch.ARM; + return Arch.getArch() != Arch.ARM && DesignerProperties.getInstance().isSupportLoginEntry(); } }, /** diff --git a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java new file mode 100644 index 000000000..2fac1e903 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java @@ -0,0 +1,135 @@ +package com.fr.design.utils; + +import com.fr.base.extension.FileExtension; +import com.fr.base.io.BaseBook; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.file.TemplateTreePane; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.worker.save.SaveFailureHandler; +import com.fr.file.FILE; +import com.fr.file.FILEChooserPane; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.ArrayUtils; +import com.fr.stable.CoreConstants; +import com.fr.stable.ProductConstants; +import com.fr.workspace.WorkContext; +import com.fr.workspace.server.lock.TplOperator; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import javax.swing.SwingWorker; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/5 + */ +public class TemplateUtils { + + public static void createAndOpenTemplate(String prefix, FILE file, boolean needOpen) { + String fileName = file.getName(); + String oldPath = file.getPath(); + int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT); + if (indexOfLastDot < 0) { + return; + } + String suffix = fileName.substring(indexOfLastDot + 1); + FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(true, true); + fileChooserPane.setFileNameTextField(prefix + fileName, suffix); + FileExtension fileExtension = FileExtension.parse(suffix); + fileChooserPane.addChooseFILEFilter(new ChooseFileFilter(fileExtension, ProductConstants.APP_NAME + Toolkit.i18nText("Fine-Design_Report_Template_File"))); + fileChooserPane.disableFileNameTextFiled(); + int result = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame(), suffix); + fileChooserPane.enableFileNameTextFiled(); + + if (isCancel(result)) { + return; + } + + if (isOk(result)) { + file = fileChooserPane.getSelectedFILE(); + _createAndOpenTemplate(file, oldPath, needOpen); + } + + } + + + private static void _createAndOpenTemplate(FILE file, String oldPath, boolean needOpen){ + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + byte[] content = new byte[0]; + if (!needOpen) { + // 从当前编辑模板中生成备份文件 + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BaseBook target = template.getTarget(); + if (target != null) { + target.export(outputStream); + content = outputStream.toByteArray(); + } + } else { + content = WorkContext.getWorkResource().readFully(oldPath); + } + if (ArrayUtils.isEmpty(content)) { + throw new Exception(oldPath + " content is empty" ); + } + OutputStream out = null; + try { + // 加锁 + WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); + out = file.asOutputStream(); + out.write(content); + } finally { + try { + if (out != null) { + out.close(); + } + } finally { + // 解锁 + WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); + } + + } + return null; + } + + @Override + protected void done() { + try { + get(); + if (needOpen) { + DesignerContext.getDesignerFrame().openTemplate(file); + } + // 备份成功刷新下目录树 展示出来备份的模板 + TemplateTreePane.getInstance().refresh(); + } catch (Exception e) { + SaveFailureHandler.getInstance().process(e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + }.execute(); + + } + + private static boolean isCancel(int result) { + return result == FILEChooserPane.CANCEL_OPTION || + result == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; + } + + private static boolean isOk(int result) { + return result == FILEChooserPane.JOPTIONPANE_OK_OPTION || + result == FILEChooserPane.OK_OPTION; + } + + public static String createLockeTemplatedName(JTemplate template, String name) { + int index = name.lastIndexOf(CoreConstants.DOT); + if (index < 0 || !template.isForbidden()) { + return name; + } + return name.substring(0, index) + Toolkit.i18nText("Fine_Design_Template_Has_Been_Locked") + name.substring(index); + } +} diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/AdjustWorkBookDefaultStyleUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/AdjustWorkBookDefaultStyleUtils.java index c26bda4cd..c3c087b4d 100644 --- a/designer-base/src/main/java/com/fr/design/utils/gui/AdjustWorkBookDefaultStyleUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/gui/AdjustWorkBookDefaultStyleUtils.java @@ -17,6 +17,7 @@ public class AdjustWorkBookDefaultStyleUtils { private static final Color TEMPLATE_BACKGROUND = new Color(16, 11, 43); private static final Color CELL_ELEMENT_BORDER = new Color(110, 110, 110); + private static final Color CELL_ELEMENT_FONT_FOREGROUND = Color.WHITE; private static Color currentStoryBack = null; @@ -31,13 +32,24 @@ public class AdjustWorkBookDefaultStyleUtils { public static void adjustCellElement(CellElement cellElement) { if (DesignModeContext.isDuchampMode()) { Style style = cellElement.getStyle(); - style = style.deriveFRFont(style.getFRFont().applyForeground(Color.WHITE)); + style = adjustCellElement(style); + cellElement.setStyle(style); + } + } + + public static Style adjustCellElement(Style style) { + if (DesignModeContext.isDuchampMode()) { + style = style.deriveFRFont(style.getFRFont().applyForeground(CELL_ELEMENT_FONT_FOREGROUND)); style = style.deriveBorder(0, CELL_ELEMENT_BORDER, 0, CELL_ELEMENT_BORDER, 0, CELL_ELEMENT_BORDER, 0, CELL_ELEMENT_BORDER); - cellElement.setStyle(style); } + return style; + } + + public static Color adjustCellElementFontForeground(Color color) { + return DesignModeContext.isDuchampMode() ? CELL_ELEMENT_FONT_FOREGROUND : color; } public static void adjustFloatElement(FloatElement floatElement) { diff --git a/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java b/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java index 40e6683eb..b070b7f07 100644 --- a/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java +++ b/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java @@ -3,18 +3,23 @@ package com.fr.design.worker.open; import com.fr.base.chart.exception.ChartNotFoundException; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.TemplateTreePane; import com.fr.design.i18n.Toolkit; +import com.fr.design.lock.LockInfoDialog; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; import com.fr.design.worker.WorkerManager; import com.fr.exception.DecryptTemplateException; +import com.fr.exception.TplLockedException; import com.fr.file.FILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; +import java.util.UUID; import javax.swing.JOptionPane; import javax.swing.SwingWorker; import javax.swing.UIManager; @@ -81,6 +86,11 @@ public class OpenWorker extends SwingWorker { JOptionPane.ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); } + if (cause.getCause() instanceof TplLockedException) { + MutilTempalteTabPane.getInstance().closeCurrentTpl(); + TemplateTreePane.getInstance().getFileNode().setLock(UUID.randomUUID().toString()); + LockInfoDialog.show(null); + } FineLoggerFactory.getLogger().error(t.getMessage(), t); return; } diff --git a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java new file mode 100644 index 000000000..4cf2af431 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java @@ -0,0 +1,113 @@ +package com.fr.design.worker.save; + +import com.fr.common.exception.ThrowableHandler; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.TemplateUtils; +import com.fr.file.FileNodeFILE; +import com.fr.file.filetree.FileNode; +import com.fr.general.IOUtils; +import com.fr.report.UnLockedException; +import com.fr.workspace.exception.DiskSpaceFullException; +import com.fr.report.InconsistentLockException; +import java.awt.Frame; +import javax.swing.JOptionPane; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/7 + */ +public class SaveFailureHandler implements ThrowableHandler { + + private static final SaveFailureHandler INSTANCE = new SaveFailureHandler(); + + public static SaveFailureHandler getInstance() { + return INSTANCE; + } + + @Override + public boolean process(Throwable e) { + for (Handler handler : Handler.values()) { + if (handler.process(e)) { + break; + } + } + return true; + } + + public enum Handler implements ThrowableHandler { + + FullDisk { + @Override + public boolean process(Throwable e) { + if (e.getCause() instanceof DiskSpaceFullException + || e instanceof DiskSpaceFullException + || e.getCause().getCause() instanceof DiskSpaceFullException) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Full_Disk"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + JOptionPane.WARNING_MESSAGE, + IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png")); + return true; + } + return false; + } + }, + UnLocked { + @Override + public boolean process(Throwable e) { + if (e.getCause() instanceof UnLockedException || e instanceof UnLockedException) { + processByBack(Toolkit.i18nText("Fine_Design_Template_Has_Been_UnLocked")); + return true; + } + return false; + } + }, + + InconsistentLock { + @Override + public boolean process(Throwable e) { + if (e.getCause() instanceof InconsistentLockException || e instanceof InconsistentLockException) { + processByBack(Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Lock_Inconsistency")); + return true; + } + return false; + } + }, + + Other { + @Override + public boolean process(Throwable e) { + boolean minimized = (DesignerContext.getDesignerFrame().getExtendedState() & Frame.ICONIFIED ) != 0; + FineJOptionPane.showMessageDialog( + minimized ? null : DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design-Basic_Save_Failure"), + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), + JOptionPane.ERROR_MESSAGE); + return true; + } + }; + + + protected void processByBack(String tip) { + int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), + tip, + Toolkit.i18nText("Fine-Design_Basic_Alert"), + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE, + IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), + new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); + if (option == JOptionPane.YES_OPTION) { + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (template != null) { + TemplateUtils.createAndOpenTemplate(Toolkit.i18nText("Fine_Design_Template_Backup"), new FileNodeFILE(new FileNode(template.getPath(), false)), false); + } + } + } + + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java b/designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java index 51a79bbad..60d797c3e 100644 --- a/designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java +++ b/designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java @@ -1,8 +1,6 @@ package com.fr.design.worker.save; -import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.EastRegionContainerPane; @@ -10,11 +8,9 @@ import com.fr.design.mainframe.JTemplate; import com.fr.design.worker.WorkerManager; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; -import java.awt.Frame; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import javax.swing.JOptionPane; import javax.swing.SwingWorker; /** @@ -55,12 +51,7 @@ public class SaveWorker extends SwingWorker { } catch (Exception e) { processResult(); FineLoggerFactory.getLogger().error(e.getMessage(), e); - boolean minimized = (DesignerContext.getDesignerFrame().getExtendedState() & Frame.ICONIFIED ) != 0; - FineJOptionPane.showMessageDialog( - minimized ? null : DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design-Basic_Save_Failure"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), - JOptionPane.ERROR_MESSAGE); + SaveFailureHandler.getInstance().process(e); return; } processResult(); diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index c21c82c75..426fd18e2 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -664,6 +664,16 @@ public class FILEChooserPane extends BasicPane { fileNameTextField.setFilter(new DefaultCompletionFilter(names)); } + public void disableFileNameTextFiled() { + fileNameTextField.setEditable(false); + fileNameTextField.setEnabled(false); + } + + public void enableFileNameTextFiled() { + fileNameTextField.setEditable(true); + fileNameTextField.setEnabled(true); + } + /** * 移除文件后缀的方法 * 解决cptx文件的另存为操作默认会出现双后缀的bug(xxx.cptx.cpt) diff --git a/designer-base/src/main/java/com/fr/start/BaseDesigner.java b/designer-base/src/main/java/com/fr/start/BaseDesigner.java index 1c4c61126..6165ff7f7 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -32,6 +32,7 @@ import com.fr.process.engine.core.CarryMessageEvent; import com.fr.process.engine.core.FineProcessContext; import com.fr.stable.OperatingSystem; +import com.fr.workspace.base.WorkspaceStatus; import java.awt.Window; import java.io.File; import java.lang.reflect.Method; @@ -84,6 +85,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { if (eventPipe != null) { eventPipe.fire(new CarryMessageEvent(ReportState.STOP.getValue())); } + EventDispatcher.fire(WorkspaceStatus.Prepared); collectUserInformation(); } }); diff --git a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java index 854d260bf..35e2090d9 100644 --- a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java +++ b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java @@ -8,8 +8,10 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.startup.FineWebApplicationInitializer; +import com.fr.third.guava.collect.Sets; import com.fr.third.springframework.web.SpringServletContainerInitializer; import com.fr.third.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import com.fr.web.socketio.WebSocketEndpoint; import com.fr.workspace.WorkContext; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; @@ -17,6 +19,7 @@ import org.apache.catalina.Wrapper; import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.webresources.StandardRoot; +import org.apache.tomcat.websocket.server.WsSci; import java.io.File; import java.util.HashSet; @@ -92,6 +95,7 @@ public class FineEmbedServerActivator extends Activator { Set> classes = new HashSet>(); classes.add(FineWebApplicationInitializer.class); context.addServletContainerInitializer(initializer, classes); + context.addServletContainerInitializer(new WsSci(), Sets.newHashSet(WebSocketEndpoint.class)); } // tomcat的maxPostSize会影响到post参数获取,默认2M diff --git a/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_disabled.svg b/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_disabled.svg new file mode 100644 index 000000000..b21c206a3 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_disabled.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_normal.svg b/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_normal.svg new file mode 100644 index 000000000..60a2855aa --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/buttonicon/select_normal.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/mainframe/lock_template.png b/designer-base/src/main/resources/com/fr/design/images/mainframe/lock_template.png new file mode 100644 index 000000000..f75bfe479 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/mainframe/lock_template.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/mainframe/refreh_icon.png b/designer-base/src/main/resources/com/fr/design/images/mainframe/refreh_icon.png new file mode 100644 index 000000000..99b4e5374 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/mainframe/refreh_icon.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/add.png b/designer-base/src/main/resources/com/fr/design/images/sort/add.png new file mode 100644 index 000000000..a14e2a40b Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/sort/add.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/asc.svg b/designer-base/src/main/resources/com/fr/design/images/sort/asc.svg new file mode 100644 index 000000000..67dd9e829 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/sort/asc.svg @@ -0,0 +1,19 @@ + + + 升序备份 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/des.svg b/designer-base/src/main/resources/com/fr/design/images/sort/des.svg new file mode 100644 index 000000000..2fcef077e --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/sort/des.svg @@ -0,0 +1,17 @@ + + + 降序 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/down_arrow.png b/designer-base/src/main/resources/com/fr/design/images/sort/down_arrow.png new file mode 100644 index 000000000..84b4909ef Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/sort/down_arrow.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/left_arrow.png b/designer-base/src/main/resources/com/fr/design/images/sort/left_arrow.png new file mode 100644 index 000000000..9166a9c96 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/sort/left_arrow.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/nosort.svg b/designer-base/src/main/resources/com/fr/design/images/sort/nosort.svg new file mode 100644 index 000000000..ca04928fc --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/sort/nosort.svg @@ -0,0 +1,41 @@ + + + 不排序 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/images/sort/sequence.png b/designer-base/src/main/resources/com/fr/design/images/sort/sequence.png new file mode 100644 index 000000000..ac321ae17 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/sort/sequence.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/lock.png b/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/lock.png new file mode 100644 index 000000000..882bbaeb3 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/lock.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/unlock.png b/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/unlock.png new file mode 100644 index 000000000..69def397e Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/toolbarbtn/unlock.png differ diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPaneWithThemeStyle.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPaneWithThemeStyle.java index 345d57de8..a29134736 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPaneWithThemeStyle.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPaneWithThemeStyle.java @@ -2,6 +2,7 @@ package com.fr.design.mainframe.chart.gui.style; import com.fr.chart.base.TextAttr; import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.gui.ibutton.UIColorButtonWithAuto; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; @@ -74,6 +75,11 @@ public class ChartTextAttrPaneWithThemeStyle extends ChartTextAttrPane { textFontPane.setVisible(preButton.getSelectedIndex() == CUSTOM); } + @Override + protected void initFontColorState() { + setFontColor(new UIColorButtonWithAuto()); + } + protected double[] getRowSize() { double p = TableLayout.PREFERRED; return new double[]{p, p}; diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java index 12e242b73..bdbdee6a8 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java @@ -11,6 +11,7 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; +import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPaneWithAuto; import com.fr.design.ui.ModernUIPane; import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.base.AttrTooltipContent; @@ -21,6 +22,7 @@ import com.fr.plugin.chart.base.format.AttrTooltipFormat; import com.fr.plugin.chart.base.format.AttrTooltipPercentFormat; import com.fr.plugin.chart.base.format.AttrTooltipSeriesFormat; import com.fr.plugin.chart.base.format.AttrTooltipValueFormat; +import com.fr.plugin.chart.type.FontAutoType; import com.fr.stable.StringUtils; import com.fr.van.chart.designer.TableLayout4VanChartHelper; import com.fr.van.chart.designer.component.format.CategoryNameFormatPaneWithCheckBox; @@ -315,7 +317,7 @@ public class VanChartTooltipContentPane extends BasicBeanPane xConnectorMap; @@ -73,8 +67,6 @@ public class XWAbsoluteLayout extends XLayoutContainer { connector = widget.getConnectorIndex(i); xConnectorMap.put(connector, new XConnector(connector, this)); } - - initPercent(widget); } /** @@ -87,36 +79,6 @@ public class XWAbsoluteLayout extends XLayoutContainer { return new Dimension(500, 300); } - //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% - private void initPercent(WAbsoluteLayout widget) { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - Dimension scrnsize = toolkit.getScreenSize(); - double screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue(); - if (!AssistUtils.equals(screenValue, FormArea.DEFAULT_SLIDER)) { - this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER); - } - } - - /** - * 返回容器大小的百分比 - * - * @return the containerPercent - */ - public double getContainerPercent() { - return containerPercent; - } - - /** - * 设置容器大小的百分比 - * - * @param containerPercent the containerPercent to set - */ - public void setContainerPercent(double containerPercent) { - this.containerPercent = containerPercent; - minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH * containerPercent); - minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT * containerPercent); - } - /** * 返回界面处根据百分比调整后的最小宽度 * @@ -142,30 +104,14 @@ public class XWAbsoluteLayout extends XLayoutContainer { */ public int getAcualInterval() { // adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数 - int interval = (int) (toData().getCompInterval() * containerPercent); + int interval = (int) (toData().getCompInterval() ); int val = interval / 2; return val * 2; } - - /** - * 界面容器大小不是默认的时,处理控件的BoundsWidget,且避免出现空隙 - */ - private Rectangle dealWidgetBound(Rectangle rec) { - if (AssistUtils.equals(1.0, containerPercent)) { - return rec; - } - rec.x = (int) (rec.x / containerPercent); - rec.y = (int) (rec.y / containerPercent); - rec.width = (int) (rec.width / containerPercent); - rec.height = (int) (rec.height / containerPercent); - return rec; - } - /** * 新增删除拉伸后单个组件的BoundsWidget */ public void updateBoundsWidget(XCreator xCreator) { - WAbsoluteLayout layout = this.toData(); if (xCreator.hasTitleStyle()) { xCreator = (XLayoutContainer) xCreator.getParent(); } @@ -223,32 +169,33 @@ public class XWAbsoluteLayout extends XLayoutContainer { } } - /** - * 更新子组件的Bound - * 这边主要用于绝对布局子组件在适应区域选项时 - * 涉及到的不同分辨率下缩放 - * - * @param minHeight 最小高度 - */ - @Override - public void updateChildBound(int minHeight) { - double prevContainerPercent = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER; - if (toData().getCompState() == 0 && !AssistUtils.equals(containerPercent, prevContainerPercent)) { - for (int i = 0; i < this.getComponentCount(); i++) { - XCreator creator = getXCreator(i); - Rectangle rec = new Rectangle(creator.getBounds()); - rec.x = (int)Math.round (rec.x / prevContainerPercent * containerPercent); - rec.y = (int)Math.round (rec.y / prevContainerPercent * containerPercent); - rec.height = (int)Math.round (rec.height / prevContainerPercent * containerPercent); - rec.width = (int)Math.round (rec.width / prevContainerPercent * containerPercent); - BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData()); - wgt.setBounds(rec); - creator.setBounds(rec); - creator.updateChildBound(minHeight); + /** + * 更新子组件的Bound + * 这边主要用于绝对布局子组件在适应区域选项时 + * 涉及到的不同分辨率下缩放 + * 兼容方法(老的模板中绝对布局带有分辨率参数的兼容处理) + * + * @param minHeight 最小高度 + */ + @Override + public void updateChildBound(int minHeight) { + double prevContainerPercent = FRScreen.getFRScreenByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER; + if (!AssistUtils.equals(DEFAULT_CONTAINER_PERCENT, prevContainerPercent)) { + for (int i = 0; i < this.getComponentCount(); i++) { + XCreator creator = getXCreator(i); + Rectangle rec = new Rectangle(creator.getBounds()); + rec.x = (int) Math.round(rec.x / prevContainerPercent); + rec.y = (int) Math.round(rec.y / prevContainerPercent); + rec.height = (int) Math.round(rec.height / prevContainerPercent); + rec.width = (int) Math.round(rec.width / prevContainerPercent); + BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData()); + wgt.setBounds(rec); + creator.setBounds(rec); + creator.updateChildBound(minHeight); + } } + toData().setDesigningResolution(FRScreen.p1440.getDimension()); } - toData().setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize()); - } /** * 增加对齐线 diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java index da4d235f0..ea6170052 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java @@ -3,15 +3,12 @@ package com.fr.design.designer.creator; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRFixLayoutAdapter; -import com.fr.design.designer.beans.adapters.layout.FRNoFixLayoutAdapter; import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.properties.mobile.BodyMobilePropertyUI; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.form.layout.FRFitLayout; import com.fr.design.fun.WidgetPropertyUIProvider; -import com.fr.design.mainframe.FormArea; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.utils.gui.LayoutUtils; @@ -24,12 +21,10 @@ import com.fr.form.ui.container.WLayout; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.stable.ArrayUtils; -import com.fr.stable.AssistUtils; import javax.swing.JOptionPane; import java.awt.Component; import java.awt.Dimension; import java.awt.Rectangle; -import java.awt.Toolkit; import java.awt.event.ContainerEvent; import java.util.ArrayList; import java.util.Arrays; @@ -46,9 +41,6 @@ public class XWFitLayout extends XLayoutContainer { private static final long serialVersionUID = 8112908607102660176L; private static final int EACH_ROW_COUNT = 4; - - //由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算 - protected double containerPercent = 1.0; // 布局缩小的时候,考虑最小宽高,若挨着右侧或底侧边框的控件缩小后达到最小宽或高,此时容器大小微调下 private int needAddWidth = 0; private int needAddHeight = 0; @@ -64,20 +56,6 @@ public class XWFitLayout extends XLayoutContainer { public XWFitLayout(WFitLayout widget, Dimension initSize) { super(widget, initSize); - - initPercent(); - - widget.setResolutionScaling(containerPercent); - } - - //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% - private void initPercent(){ - Toolkit toolkit = Toolkit.getDefaultToolkit(); - Dimension scrnsize = toolkit.getScreenSize(); - double screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue(); - if (!AssistUtils.equals(FormArea.DEFAULT_SLIDER, screenValue)) { - this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER); - } } @Override @@ -252,19 +230,16 @@ public class XWFitLayout extends XLayoutContainer { * @return int[] 横坐标数组 */ public int[] getHors(boolean isActualSize) { - double perc = isActualSize ? containerPercent : 1.0; List posX = new ArrayList(); // 保存实际大小时,组件大小已经去除内边距,此处也判断下 - PaddingMargin margin = isActualSize ? new PaddingMargin(0,0,0,0) : toData().getMargin(); + PaddingMargin margin = isActualSize ? new PaddingMargin(0, 0, 0, 0) : toData().getMargin(); posX.add(margin.getLeft()); int width = this.getWidth() - margin.getLeft() - margin.getRight(); - int containW = (int) (width / perc); - posX.add(containW + margin.getLeft()); - for (int i=0, len=this.getComponentCount(); i < len; i++) { + posX.add(width + margin.getLeft()); + for (int i = 0, len = this.getComponentCount(); i < len; i++) { int x = this.getComponent(i).getX(); - int finalX = (int) (x / perc); - if (!posX.contains(finalX)) { - posX.add(finalX); + if (!posX.contains(x)) { + posX.add(x); } } Collections.sort(posX); @@ -278,19 +253,16 @@ public class XWFitLayout extends XLayoutContainer { * */ public int[] getVeris(boolean isActualSize) { - double perc = isActualSize ? containerPercent : 1.0; List posY = new ArrayList(); // 保存实际大小时,组件大小已经去除内边距,此处也判断下 PaddingMargin margin = isActualSize ? new PaddingMargin(0,0,0,0) : toData().getMargin(); posY.add(margin.getTop()); int height = this.getHeight() - margin.getTop() - margin.getBottom(); - int containH = (int) (height / perc); - posY.add(containH + margin.getTop()); + posY.add(height + margin.getTop()); for (int i=0, len=this.getComponentCount(); i < len; i++) { int y = this.getComponent(i).getY(); - int finalY = (int) (y / perc); - if (!posY.contains(finalY)) { - posY.add(finalY); + if (!posY.contains(y)) { + posY.add(y); } } Collections.sort(posY); @@ -721,34 +693,6 @@ public class XWFitLayout extends XLayoutContainer { creator.setBackupParent(this); } - /** - * 界面容器大小不是默认的时,处理控件的BoundsWidget,且避免出现空隙 - */ - private Rectangle dealWidgetBound(Rectangle rec) { - if (AssistUtils.equals(1.0, containerPercent)) { - return rec; - } - rec.x = (int) (rec.x/containerPercent); - rec.y = (int) (rec.y/containerPercent); - rec.width = (int) (rec.width/containerPercent); - rec.height = (int) (rec.height/containerPercent); - return rec; - } - - /** - * 界面容器大小不是默认的时,恢复组件实际大小 - */ - private Rectangle dealWgtBound(Rectangle rec) { - if (AssistUtils.equals(1.0, containerPercent)) { - return rec; - } - rec.x = (int) (rec.x * containerPercent); - rec.y = (int) (rec.y * containerPercent); - rec.width = (int) (rec.width * containerPercent); - rec.height = (int) (rec.height * containerPercent); - return rec; - } - /** * 新增删除拉伸后更新每个组件的BoundsWidget */ @@ -774,7 +718,7 @@ public class XWFitLayout extends XLayoutContainer { XCreator creator = (XCreator) this.getComponent(index); BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData()); // 用当前的显示大小计算后调正具体位置 - Rectangle wgtBound = dealWidgetBound(creator.getBounds()); + Rectangle wgtBound = creator.getBounds(); Rectangle rec = recalculateWidgetBounds(wgtBound, hors, veris); wgt.setBounds(rec); creator.toData().updateChildBounds(rec); @@ -814,7 +758,7 @@ public class XWFitLayout extends XLayoutContainer { //更新的时候一定要带上backupBound if (creator.getBackupBound() == null && wgt.getBeforeScaleBounds() != null) { - creator.setBackupBound(dealWgtBound(wgt.getBeforeScaleBounds())); + creator.setBackupBound(wgt.getBeforeScaleBounds()); } ((XWAbsoluteLayout) creator).updateBoundsWidget(); creator.setBackupBound(creator.getBounds()); @@ -1170,24 +1114,6 @@ public class XWFitLayout extends XLayoutContainer { return this.getComponentAt(x+w-default_Length, y+h+default_Length+val); } - /** - * 返回容器大小的百分比 - * @return the containerPercent - */ - public double getContainerPercent() { - return containerPercent; - } - - /** - * 设置容器大小的百分比 - * @param containerPercent the containerPercent to set - */ - public void setContainerPercent(double containerPercent) { - this.containerPercent = containerPercent; - minWidth = (int) (XWFitLayout.MIN_WIDTH*containerPercent); - minHeight = (int) (XWFitLayout.MIN_HEIGHT*containerPercent); - } - /** * 该组件是否可以拖拽(表单中参数面板和自适应布局不可以拖拽) * @return 是则返回true @@ -1218,9 +1144,9 @@ public class XWFitLayout extends XLayoutContainer { */ public int getAcualInterval() { // adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数 - int interval = (int) (toData().getCompInterval()*containerPercent); - int val = interval/2; - return val*2; + int interval = toData().getCompInterval(); + int val = interval / 2; + return val * 2; } /** diff --git a/designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java b/designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java index 7e2fd9451..fb0ab8718 100644 --- a/designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java +++ b/designer-form/src/main/java/com/fr/design/designer/properties/FRFitLayoutConstraints.java @@ -92,8 +92,8 @@ public class FRFitLayoutConstraints implements ConstraintsGroupModel { Rectangle bounds = getBounds(); Rectangle rec = ComponentUtils.getRelativeBounds(parent); WFitLayout wFitLayout = parent.toData(); - int minHeight = (int)(MINHEIGHT * wFitLayout.getResolutionScaling()); - int minWidth = (int)(MINWIDTH * wFitLayout.getResolutionScaling()); + int minHeight = MINHEIGHT; + int minWidth = MINWIDTH; PaddingMargin margin= wFitLayout.getMargin(); switch (row) { case 0: diff --git a/designer-form/src/main/java/com/fr/design/fit/JFormType.java b/designer-form/src/main/java/com/fr/design/fit/JFormType.java index f2d1c4ad9..52c8f728c 100644 --- a/designer-form/src/main/java/com/fr/design/fit/JFormType.java +++ b/designer-form/src/main/java/com/fr/design/fit/JFormType.java @@ -1,30 +1,10 @@ package com.fr.design.fit; -import com.fr.design.beans.BasicBeanPane; -import com.fr.design.fit.common.AdaptiveSwitchUtil; -import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.fit.config.FormFitConfig; -import com.fr.design.fit.menupane.FormFitAttrPane; -import com.fr.design.fun.PreviewProvider; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.preview.FormAdaptivePreview; -import com.fr.design.preview.FormPreview; -import com.fr.design.report.fit.menupane.ReportFitAttrPane; -import com.fr.form.main.Form; import com.fr.report.fit.ReportFitAttr; public enum JFormType { - OLD_TYPE(0, new FormPreview()) { - @Override - public void switchUI() { - AdaptiveSwitchUtil.switch2OldUI(); - } - - @Override - public void switchUIMode() { - AdaptiveSwitchUtil.switch2OldUIMode(); - } - + OLD_TYPE(0) { @Override public ReportFitAttr obtainFitAttr() { return FormFitConfig.getInstance().getOldFitAttr(); @@ -35,23 +15,9 @@ public enum JFormType { FormFitConfig.getInstance().setOldFitAttr(attr); } - @Override - public BasicBeanPane obtainAttrPane(NewJForm newJForm) { - return new ReportFitAttrPane(); - } }, - NEW_TYPE(1, new FormAdaptivePreview()) { - @Override - public void switchUI() { - AdaptiveSwitchUtil.switch2NewUI(); - } - - @Override - public void switchUIMode() { - AdaptiveSwitchUtil.switch2NewUIMode(); - } - + NEW_TYPE(1) { @Override public ReportFitAttr obtainFitAttr() { return FormFitConfig.getInstance().getNewFitAttr(); @@ -62,80 +28,35 @@ public enum JFormType { FormFitConfig.getInstance().setNewFitAttr(attr); } - @Override - public BasicBeanPane obtainAttrPane(NewJForm newJForm) { - return new FormFitAttrPane(newJForm); - } }; - private int type; - private boolean newType; - private PreviewProvider defaultPreviewType; + private final int type; + private final boolean newType; - JFormType(int type, PreviewProvider defaultPreviewType) { + JFormType(int type) { this.type = type; this.newType = (type == 1); - this.defaultPreviewType = defaultPreviewType; } public int getType() { return type; } - public boolean isNewType() { - return newType; - } - public PreviewProvider getDefaultPreviewType() { - return defaultPreviewType; + public static JFormType parseFormType(int type) { + for (JFormType formType : values()) { + if (formType.getType() == type) { + return formType; + } + } + return JFormType.OLD_TYPE; } - public abstract void switchUI(); - - public abstract void switchUIMode(); + public boolean isNewType() { + return newType; + } public abstract ReportFitAttr obtainFitAttr(); public abstract void updateFitAttr(ReportFitAttr attr); - public abstract BasicBeanPane obtainAttrPane(NewJForm newJForm); - - /** - * @Description: 更新模板的标志位 - * @param jTemplate - * @return: - * @Author: Henry.Wang - * @date: 2020/12/17 16:17 - */ - public void updateJFromTemplateType(JTemplate jTemplate) { - if (jTemplate instanceof NewJForm) { - NewJForm newJForm = (NewJForm) jTemplate; - Form form = newJForm.getTarget(); - NewFormMarkAttr newFormMarkAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); - if (newFormMarkAttr == null) { - newFormMarkAttr = new NewFormMarkAttr(this.getType()); - form.addAttrMark(newFormMarkAttr); - } - newFormMarkAttr.setType(this.getType()); - newJForm.setJFormType(this); - } - } - - /** - * @Description: 更新预览方式 - * @param jTemplate - * @return: - * @Author: Henry.Wang - * @date: 2020/12/17 16:17 - */ - public void updatePreviewType(JTemplate jTemplate) { - if (jTemplate.getPreviewType() != null) { - PreviewProvider[] previewProviders = jTemplate.supportPreview(); - for (PreviewProvider previewProvider : previewProviders) { - if (previewProvider.getClass() == jTemplate.getPreviewType().getClass()) { - return; - } - } - } - jTemplate.setPreviewType(this.getDefaultPreviewType()); - } } diff --git a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java index 6859c1231..9df0806de 100644 --- a/designer-form/src/main/java/com/fr/design/fit/NewJForm.java +++ b/designer-form/src/main/java/com/fr/design/fit/NewJForm.java @@ -2,19 +2,18 @@ package com.fr.design.fit; import com.fr.base.DynamicUnitList; import com.fr.base.Parameter; -import com.fr.design.actions.TemplateParameterAction; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter; import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.*; -import com.fr.design.fit.common.AdaptiveSwitchUtil; -import com.fr.design.fit.common.LayoutTool; -import com.fr.form.fit.NewFormMarkAttr; -import com.fr.design.fit.common.TemplateTool; -import com.fr.design.actions.NewFormMobileAttrAction; +import com.fr.design.designer.creator.XComponent; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.designer.creator.XElementCase; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.preview.DeveloperPreview; import com.fr.design.preview.FormAdaptivePreview; import com.fr.design.fit.toolbar.SwitchAction; @@ -22,14 +21,13 @@ import com.fr.design.fun.PreviewProvider; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.WidgetPropertyPane; -import com.fr.design.menu.ShortCut; import com.fr.design.preview.FormPreview; import com.fr.design.preview.MobilePreview; import com.fr.design.utils.ComponentUtils; import com.fr.file.FILE; import com.fr.form.FormElementCaseProvider; +import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.main.Form; -import com.fr.form.main.mobile.FormMobileAttr; import com.fr.form.ui.ElementCaseEditor; import com.fr.stable.ArrayUtils; @@ -49,13 +47,13 @@ public class NewJForm extends JForm { public NewJForm() { super(); init(); - changePaneSize(); } public NewJForm(Form form) { super(form); init(); - changePaneSize(); + //新建的模板都要加上新表单标志attr + form.addAttrMark(NewFormMarkAttr.createNewFormAttr()); } public NewJForm(Form form, FILE file, Parameter[] parameters) { @@ -64,51 +62,7 @@ public class NewJForm extends JForm { public NewJForm(Form form, FILE file) { super(form, file); - if (DesignerUIModeConfig.getInstance().newUIMode()) { - init(); - } - changePaneSize(); - } - - /** - * @Description:改变body的大小,主要针对新模式下打开老模板出现截断的情况 - * @param - * @return: - * @Author: Henry.Wang - * @date: 2020/9/13 23:23 - */ - private void changePaneSize() { - NewFormMarkAttr newFormMarkAttr = this.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG); - if (newFormMarkAttr.isNotSetOriginSize()) { - newFormMarkAttr.setBodyHeight(LayoutTool.getBodyHeight(this)); - newFormMarkAttr.setBodyWidth(LayoutTool.getBodyWidth(this)); - return; - } - //这种是针对body为绝对布局时,可能出现截断的情况 - if (LayoutTool.absoluteLayoutForm(this)) { - int bodyHeight = newFormMarkAttr.getBodyHeight(); - int bodyWidth = newFormMarkAttr.getBodyWidth(); - Rectangle rectangle = LayoutTool.getAbsoluteBodySize(this); - if (!isNewJFrom() && (rectangle.width != bodyWidth || rectangle.height != bodyHeight)) { - TemplateTool.onlyChangeAbsoluteBodySize(bodyHeight, bodyWidth, this); - } else if (isNewJFrom()) { - if (rectangle.width > bodyWidth && rectangle.height > bodyHeight) { - TemplateTool.onlyChangeAbsoluteBodySize(rectangle.height, rectangle.width, this); - } else if (rectangle.width > bodyWidth) { - TemplateTool.onlyChangeAbsoluteBodySize(bodyHeight, rectangle.width, this); - } else if (rectangle.height > bodyHeight) { - TemplateTool.onlyChangeAbsoluteBodySize(rectangle.height, bodyWidth, this); - } - } - } else if (AdaptiveSwitchUtil.isSwitchJFromIng()) { - //这种是针对body中有绝对画布块,导致截断的情况 - double scale = LayoutTool.getContainerPercent(); - if (isNewJFrom()) { - LayoutTool.scaleAbsoluteBlockComponentsBounds(this.getFormDesign().getRootComponent(), 1 / scale); - } else { - LayoutTool.scaleAbsoluteBlockComponentsBounds(this.getFormDesign().getRootComponent(), scale); - } - } + init(); } public JFormType getJFormType() { @@ -119,22 +73,6 @@ public class NewJForm extends JForm { this.jFormType = jFormType; } - - /** - * 模板菜单 - * - * @return 返回菜单 - */ - @Override - public ShortCut[] shortcut4TemplateMenu() { - if (this.index == FORM_TAB) { - return ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new NewFormMobileAttrAction(this), getReportFitAttrAction()}, new ShortCut[0]); - } else { - return ArrayUtils.addAll(new ShortCut[]{new TemplateParameterAction(this), new NewFormMobileAttrAction(this), getReportFitAttrAction()}, this.getElementCaseDesign().shortcut4TemplateMenu()); - } - } - - private void init() { this.getFormDesign().addDesignerEditListener(new DesignerEditListener() { private Rectangle oldRec; @@ -247,6 +185,13 @@ public class NewJForm extends JForm { } }); + + Form form = this.getTarget(); + NewFormMarkAttr newFormMarkAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); + if (newFormMarkAttr == null) { + newFormMarkAttr = new NewFormMarkAttr(); + } + this.setJFormType(JFormType.parseFormType(newFormMarkAttr.getType())); } @@ -270,24 +215,14 @@ public class NewJForm extends JForm { return new PreviewProvider[]{new FormPreview(), new MobilePreview()}; } - public boolean mobileForm() { - FormMobileAttr mobileAttr = this.getTarget().getFormMobileAttr(); - if (mobileAttr.isMobileOnly() && mobileAttr.isAdaptivePropertyAutoMatch()) { - return true; - } - return false; - } - - private SwitchAction switchAction; - public UIButton[] createExtraButtons() { UIButton[] extraButtons = super.createExtraButtons(); return addAdaptiveSwitchButton(extraButtons); } private UIButton[] addAdaptiveSwitchButton(UIButton[] extraButtons) { - switchAction = new SwitchAction(); - return ArrayUtils.addAll(extraButtons, new UIButton[]{switchAction.getToolBarButton()}); + SwitchAction switchAction = new SwitchAction(this); + return ArrayUtils.addAll(extraButtons, switchAction.getToolBarButton()); } public boolean isNewJFrom() { diff --git a/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java b/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java index a5df5fabd..031d69849 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/AdaptiveSwitchUtil.java @@ -1,15 +1,14 @@ package com.fr.design.fit.common; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fit.NewJForm; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; import com.fr.design.preview.FormAdaptivePreview; import com.fr.design.preview.FormPreview; import com.fr.file.FILE; import com.fr.file.MemFILE; +import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.main.Form; import com.fr.form.main.WidgetGather; import com.fr.form.ui.Widget; @@ -33,25 +32,10 @@ public class AdaptiveSwitchUtil { } - public static void switch2NewUI() { - switch2NewUIMode(); - reload(); - } - - public static void switch2NewUIMode() { - DesignerUIModeConfig.getInstance().setNewUIMode(); - } - - public static void switch2OldUI() { - switch2OldUIMode(); - reload(); - } - - public static void switch2OldUIMode() { - DesignerUIModeConfig.getInstance().setOldUIMode(); - } - - public static void reload() { + /** + * 新老表单转换的方法 + */ + public static void switchReload() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -61,15 +45,15 @@ public class AdaptiveSwitchUtil { return; } JTemplate old = TemplateTool.getCurrentEditingTemplate(); - if (old == null || !(old instanceof JForm)) { + if (!(old instanceof NewJForm)) { return; } - JTemplate template = createNewJTemplate(old); + JTemplate template = createNewJTemplate((NewJForm) old); if (template != null) { DesignTableDataManager.closeTemplate(old); TemplateTool.resetTabPaneEditingTemplate(template); TemplateTool.activeAndResizeTemplate(template); - setPreviewType(); + setPreviewType(template); } } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage()); @@ -83,14 +67,12 @@ public class AdaptiveSwitchUtil { /** * @Description: 设置预览方式 - * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/10/13 14:08 */ - private static void setPreviewType() { - JTemplate jTemplate = TemplateTool.getCurrentEditingTemplate(); + private static void setPreviewType(JTemplate jTemplate) { if (jTemplate != null) { - if (DesignerUIModeConfig.getInstance().newUIMode()) { + if (TemplateTool.isNewJForm(jTemplate)) { jTemplate.setPreviewType(new FormAdaptivePreview()); } else { jTemplate.setPreviewType(new FormPreview()); @@ -99,29 +81,30 @@ public class AdaptiveSwitchUtil { } /** + * @param oldForm 以前的模板 * @Description: 创建模板 - * @param old 以前的模板 * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/9/6 14:08 */ - public static JTemplate createNewJTemplate(JTemplate old) { - JTemplate template; - template = createNewJTemplateInternal(old); - if (template instanceof NewJForm) { - NewJForm jForm = ((NewJForm) template); - //如果是从旧的设计模板转化为新的设计模式,并且不是全局配置的模板。则更新新模板的Pc端自适应属性 - if (DesignerUIModeConfig.getInstance().newUIMode() && jForm.getTarget().getReportFitAttr() != null && isSwitchJFromIng()) { - jForm.getTarget().setReportFitAttr(shiftReportFitAttr(old, jForm.getTarget().getReportFitAttr().isFitFont())); - } - processAbsoluteLayoutCompatible(jForm.getTarget()); - TemplateTool.saveForm(jForm); + public static JTemplate createNewJTemplate(NewJForm oldForm) { + NewJForm newJForm = createNewJTemplateInternal(oldForm); + if (newJForm == null) { + return null; + } + //如果是从旧的设计模板转化为新的设计模式,并且不是全局配置的模板。则更新新模板的Pc端自适应属性 + if (newJForm.getTarget().getReportFitAttr() != null && newJForm.isNewJFrom()) { + //修改自适应属性 + newJForm.getTarget().setReportFitAttr(shiftReportFitAttr(oldForm, newJForm.getTarget().getReportFitAttr().isFitFont())); + //修改绝对布局中的缩放属性 + processAbsoluteLayoutCompatible(newJForm.getTarget()); } - return template; + TemplateTool.saveForm(newJForm); + return newJForm; } - private static void processAbsoluteLayoutCompatible(Form form){ + private static void processAbsoluteLayoutCompatible(Form form) { Form.traversalWidget(form.getContainer(), new WidgetGather() { @Override public void dealWith(Widget widget) { @@ -141,25 +124,28 @@ public class AdaptiveSwitchUtil { } - /** - * @Description: 创建模板核心方法 * @param old 以前的方法 + * @Description: 创建模板核心方法 * @return: 新创建的模板 * @Author: Henry.Wang * @date: 2020/9/6 14:09 */ - private static JTemplate createNewJTemplateInternal(JTemplate old) { + private static NewJForm createNewJTemplateInternal(JTemplate old) { FILE file = old.getEditingFILE(); if ((file instanceof MemFILE) || !old.isSaved()) { - if (old instanceof NewJForm) { - TemplateTool.resetAbsoluteBodySize((NewJForm) old); - } TemplateTool.saveForm(old); } if (old.getTarget() instanceof Form) { try { - return new NewJForm((Form) (old.getTarget()).clone(), old.getEditingFILE()); + //这边进行数据模型中的标志位切换 + Form form = (Form) old.getTarget().clone(); + NewFormMarkAttr oldFormAttr = form.getAttrMark(NewFormMarkAttr.XML_TAG); + if (oldFormAttr == null) { + oldFormAttr = new NewFormMarkAttr(); + } + form.addAttrMark(oldFormAttr.switchAttr()); + return new NewJForm(form, old.getEditingFILE()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e, e.getMessage()); return null; @@ -170,46 +156,43 @@ public class AdaptiveSwitchUtil { } /** - * @Description: 老模板切换到新模板的属性配置转换( - * 1、绝对布局-适应区域--》双向自适应 - * 2、自适应布局-双向自适应--》双向自适应 - * 3、自适应布局-横向自适应--》横向自适应 - * 4、绝对布局-固定大小--》不自适应 - * ) * @param old * @param fitFont 字体是否自适应 + * @Description: 老模板切换到新模板的属性配置转换( + * 1、绝对布局-适应区域--》双向自适应 + * 2、自适应布局-双向自适应--》双向自适应 + * 3、自适应布局-横向自适应--》横向自适应 + * 4、绝对布局-固定大小--》不自适应 + * ) * @return: * @Author: Henry.Wang * @date: 2020/9/6 14:01 */ - private static ReportFitAttr shiftReportFitAttr(JTemplate old, boolean fitFont) { - if (old instanceof JForm && DesignerUIModeConfig.getInstance().newUIMode()) { - JForm jForm = (JForm) old; - try { - int layoutType = LayoutTool.getFormLayoutType(jForm); - int compState = -1; - //自适应布局 - if (layoutType == 0) { - compState = ((WFitLayout) jForm.getFormDesign().getRootComponent().toData()).getCompState(); - if (compState == WFitLayout.STATE_FULL) { - return new ReportFitAttr(2, fitFont); - } else if (compState == WFitLayout.STATE_ORIGIN) { - return new ReportFitAttr(1, fitFont); - } - } else if (layoutType == 1) {//绝对布局 - Widget widget = ((CRBoundsWidget) jForm.getFormDesign().getRootComponent().toData().getWidget(0)).getWidget(); - if (widget instanceof WAbsoluteLayout) { - compState = ((WAbsoluteLayout) widget).getCompState(); - } - if (compState == WAbsoluteLayout.STATE_FIT) { - return new ReportFitAttr(2, fitFont); - } else if (compState == WAbsoluteLayout.STATE_FIXED) { - return new ReportFitAttr(3, fitFont); - } + private static ReportFitAttr shiftReportFitAttr(NewJForm old, boolean fitFont) { + try { + int layoutType = LayoutTool.getFormLayoutType(old); + int compState = -1; + //自适应布局 + if (layoutType == 0) { + compState = ((WFitLayout) old.getFormDesign().getRootComponent().toData()).getCompState(); + if (compState == WFitLayout.STATE_FULL) { + return new ReportFitAttr(2, fitFont); + } else if (compState == WFitLayout.STATE_ORIGIN) { + return new ReportFitAttr(1, fitFont); + } + } else if (layoutType == 1) {//绝对布局 + Widget widget = ((CRBoundsWidget) old.getFormDesign().getRootComponent().toData().getWidget(0)).getWidget(); + if (widget instanceof WAbsoluteLayout) { + compState = ((WAbsoluteLayout) widget).getCompState(); + } + if (compState == WAbsoluteLayout.STATE_FIT) { + return new ReportFitAttr(2, fitFont); + } else if (compState == WAbsoluteLayout.STATE_FIXED) { + return new ReportFitAttr(3, fitFont); } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } return null; } diff --git a/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java b/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java deleted file mode 100644 index 829d320e8..000000000 --- a/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java +++ /dev/null @@ -1,1266 +0,0 @@ -package com.fr.design.fit.common; - -import com.fr.base.AutoChangeLineAndDrawManager; -import com.fr.base.FRContext; -import com.fr.base.GraphHelper; -import com.fr.base.Style; -import com.fr.base.SynchronizedLiveDataModelUtils; -import com.fr.base.TableData; -import com.fr.base.regist.LicenseConfigManager; -import com.fr.config.ServerPreferenceConfig; -import com.fr.data.api.TableDataAssist; -import com.fr.design.fit.PX; -import com.fr.general.ComparatorUtils; -import com.fr.general.FArray; -import com.fr.general.FRFont; -import com.fr.general.GeneralContext; -import com.fr.general.GeneralUtils; -import com.fr.general.IOUtils; -import com.fr.general.data.DataModel; -import com.fr.general.data.TableDataException; -import com.fr.general.xml.GeneralXMLTools; -import com.fr.json.JSONArray; -import com.fr.json.JSONException; -import com.fr.json.JSONObject; -import com.fr.json.JSONUtils; -import com.fr.json.revise.EmbedJson; -import com.fr.locale.InterProviderFactory; -import com.fr.log.FineLoggerFactory; -import com.fr.plugin.injectable.PluginModule; -import com.fr.report.fun.VerticalTextProcessor; -import com.fr.report.fun.impl.DefaultVerticalTextProcessor; -import com.fr.script.Calculator; -import com.fr.stable.ColumnRow; -import com.fr.stable.Constants; -import com.fr.stable.GraphDrawHelper; -import com.fr.stable.ListSet; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; -import com.fr.stable.bridge.ObjectHolder; -import com.fr.stable.fun.AutoChangeLineAndDrawProcess; -import com.fr.stable.fun.FontProcessor; -import com.fr.stable.plugin.ExtraClassManagerProvider; -import com.fr.stable.project.ProjectConstants; -import com.fr.stable.script.CalculatorProvider; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.UNIT; -import com.fr.workspace.WorkContext; - -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JFrame; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Paint; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.image.BufferedImage; -import java.awt.image.CropImageFilter; -import java.awt.image.FilteredImageSource; -import java.io.IOException; -import java.io.InputStream; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; - - -/** - * 基本的工具类 - */ -public class BaseUtils { - - private BaseUtils() { - } - - /** - * 从缓存中读取图片(如果缓存中存在的话则直接从缓存中读取,如果不存在则从磁盘读取并将读取的结果缓存起来) - * - * @param resource 图片的路径 - * @return 图片 - * @see IOUtils#readImageWithCache(String) - * @deprecated - */ - public static BufferedImage readImageWithCache(String resource) { - return IOUtils.readImageWithCache(resource); - } - - /** - * 从缓存中读取图片,如果缓存中不存在则返回null - * - * @param resource 图片路径 - * @return 图片,缓存中没有则返回null - * @see IOUtils#readCacheImage(String) - * @deprecated - */ - public static BufferedImage readCacheImage(String resource) { - return IOUtils.readCacheImage(resource); - } - - /** - * 直接从磁盘中读取图片,这种方法效率稍低但每次图片更改了也能即时反应出来 - * - * @param resource 图片的路径 - * @return 图片 - * @see IOUtils#readImage(String) - * @deprecated - */ - public static BufferedImage readImage(String resource) { - //daniel bug 5400 图片读取 默认关闭缓存 - return IOUtils.readImage(resource); - } - - /** - * 读取图标,该方法启用了缓存 - * - * @param resource 图标文件的存放路径 - * @return 图标 - * @see IOUtils#readIcon(String) - * @deprecated - */ - public static Icon readIcon(String resource) { - return IOUtils.readIcon(resource); - } - - /** - * 从输入流中读取图片 - * - * @param input 输入流 - * @return 图片 - * @throws IOException - * @see IOUtils#readImage(InputStream) - * @deprecated - */ - public static BufferedImage readImage(InputStream input) throws IOException { - return IOUtils.readImage(input); - } - - /** - * 将行列对象转换成其字符串的表示形式 - * 转换后的字符串将像A2,B4,C45这样的 - *

- * 将A1单元格转化成字符串"A1": - *

- * BaseUtils.convertColumnRowToCellString(ColumnRow.valueOf(0,0)); - * - * @param columnRow 要转换的行列对象 - * @return 表示行列位置的字符串 - */ - public static String convertColumnRowToCellString(ColumnRow columnRow) { - if (columnRow == null) { - return ""; - } - - return columnRow.toString(); - } - - /** - * 将表示行列位置的字符串转换成行列对象 - * 如果转换失败,将会返回{@link ColumnRow} - * - * @param columnRowString 表示行列位置的字符串对象 - * @return 行列对象 - * @see ColumnRow#valueOf(String) - * @deprecated - */ - public static ColumnRow convertCellStringToColumnRow(String columnRowString) { - return ColumnRow.valueOf(columnRowString); - } - - /** - * 读取jar的版本号 - * - * @return 版本号 - * @see GeneralUtils#readBuildNO() - * @deprecated - */ - public static String readBuildNO() { - return GeneralUtils.readBuildNO(); - } - - /** - * 把指定位置的资源以默认的GBK编码的形式读取成字符串 - * - * @param path 资源存放的路径 - * @return 表示资源内容的字符串 - * @see IOUtils#readResourceAsString(String) - * @deprecated - */ - public static String readResourceAsString(String path) { - return IOUtils.readResourceAsString(path); - } - - /** - * 将指定位置的资源以指定的编码形式读取成字符串 - * - * @param path 资源存放的路径 - * @param encode 读取资源所用的编码 - * @return 表示资源内容的字符串 - * @see IOUtils#readResourceAsString(String, String) - * @deprecated - */ - public static String readResourceAsString(String path, String encode) { - return IOUtils.readResourceAsString(path, encode); - } - - @Deprecated - public static String[] getDependence(Object value, CalculatorProvider c) { - - try { - return (String[]) StableUtils.invokeMethod("com.fr.form.FormUtils", "getDependence", new Class[]{Object.class, CalculatorProvider.class}, new Object[]{value, c}); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return null; - } - - /** - * 读取资源 - * - * @param path 资源存放的路径,可以是一个URL - * @return 返回资源的输入流 - * @see IOUtils#readResource(String) - * @deprecated - */ - public static InputStream readResource(String path) { - return IOUtils.readResource(path); - } - - /** - * 截取图片的指定区域作为一个图标 - * - * @param image 原始的图片 - * @param startx 截取的横向起始位置 - * @param starty 截取的纵向起始位置 - * @param width 截取的图标的宽度 - * @param height 截取的图标的高度 - * @return 图标 - */ - public static ImageIcon createIcon(Image image, int startx, int starty, int width, int height) { - JFrame jc = new JFrame(); - Image cropImage = jc.createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(startx, starty, width, height))); - return new ImageIcon(cropImage); - } - - /** - * 将一个长整形数组以指定的分隔符转化成一个字符串 - * - * @param array 数组 - * @param decimal 分隔符 - * @return 表示数组的字符串 - */ - public static String toLongArrayString(long[] array, char decimal) { - StringBuffer sb = new StringBuffer(); - if (array != null) { - for (int i = 0; i < array.length; i++) { - if (i != 0) { - sb.append(decimal); - } - sb.append(array[i]); - } - } - return sb.toString(); - } - - /** - * 将一个有规则的字符串按指定的分隔符分割并转化成一个长整型数组 - * - * @param str 有规则的字符串 - * @param decimal 分隔符 - * @return 长整型数组 - */ - public static long[] toLongArrayFromStr(String str, char decimal) { - List list = new ArrayList(); - if (str == null) { - return new long[0]; - } - String[] strarray = StableUtils.splitString(str, String.valueOf(decimal)); - for (int i = 0; i < strarray.length; i++) { - String text = strarray[i].trim(); - list.add(Long.valueOf(text)); - } - - long[] res = new long[list.size()]; - for (int i = 0; i < res.length; i++) { - res[i] = ((Long) list.get(i)).longValue(); - } - - return res; - } - - - /** - * 获取样式中字体的类型 - * - * @param g2d 图形上下文 - * @param style 样式 - * @param resolution 屏幕分辨率 - * @return 字体 - */ - public static Font getStyleFont(Graphics2D g2d, Style style, int resolution) { - FRFont font = style.getFRFont(); - Font rfont = initFontWithLocaleAndG2d(g2d, font, resolution); - if (!ComparatorUtils.equals(rfont, g2d.getFont())) { - g2d.setFont(rfont); - } - Color foreground = font.getForeground(); - if (!ComparatorUtils.equals(foreground, g2d.getPaint())) { - g2d.setPaint(foreground); - } - - return rfont; - } - - - private static Font initFontWithLocaleAndG2d(Graphics2D g2d, FRFont font, int resolution) { - Locale locale = GeneralContext.getLocale(); - Font rfont; - if (ComparatorUtils.equals(Locale.ENGLISH, locale)) { - rfont = FRFont.getInstance("Dialog", font.getStyle(), font.getSize()); - } - - rfont = font.applyResolutionNP(resolution); - //itext的bug 用SimSun导出无法实现粗体斜体, 其作者解释是使用basefont是不支持这些style的, 要转成itext的亚洲字体 - //这边不用instance of的原因就是不想把itext包引到applet包里面去. - if (g2d.toString().indexOf("PdfGraphics2D") != -1 && ComparatorUtils.equals(FRFont.DEFAULT_FONTNAME, font.getName())) { - //不要把这边的'宋体'改成'Simsun', 就这么设定的 - rfont = FRFont.getInstance(InterProviderFactory.getProvider().getLocText("Fine-Core_Base_Song_TypeFace"), rfont.getStyle(), rfont.getSize(), - font.getForeground(), font.getUnderline(), font.isStrikethrough(), font.isShadow(), - font.isSuperscript(), font.isSubscript()); - } - - return rfont; - } - - /** - * 获取样式中关于水平方向上的对齐类型 - * - * @param style 样式 - * @return 水平方向上的对齐类型 - */ - public static int getAlignment4Horizontal(Style style) { - return getAlignment4Horizontal(style, null); - } - - /** - * 获取DataMoodel中第columnIndex列的数据. - * - * @param model 取数的数据来源 - * @param columnIndex 取数的数据列序号 - * @return 返回数据数组Object[] - */ - public static Object[] getDistinctValues(DataModel model, int columnIndex) throws TableDataException { - ListSet list = new ListSet(); - if (columnIndex != DataModel.COLUMN_NAME_NOT_FOUND) { - for (int i = 0, len = model.getRowCount(); i < len; i++) { - list.add(model.getValueAt(i, columnIndex)); - } - } - - return list.toArray(); - } - - /** - * 获取水平方向上的对齐样式 - * - * @param style 样式 - * @param value 单元格的值,默认情况下,当不设置对齐类型时,如果单元格的值是数字则靠右对齐,字符串则靠左对齐 - * @return 水平方向上的对齐样式 - */ - public static int getAlignment4Horizontal(Style style, Object value) { - int horizontalAlignment = style.getHorizontalAlignment(); - //若是默认值:判断 bug5188 数字居右 - if (value != null && horizontalAlignment == Constants.NULL) { - if (value instanceof String) { - if (style.getFormat() instanceof NumberFormat || StableUtils.isNumber((String) value)) { - horizontalAlignment = Constants.RIGHT; - } else { - //字符串:靠左 - horizontalAlignment = Constants.LEFT; - } - } else if (value instanceof Number) { - horizontalAlignment = Constants.RIGHT; - } - } - return horizontalAlignment; - } - - /** - * 基本的画文本的方法,只考虑样式中的字体和对齐方式 - * - * @param g2d 图形上下文 - * @param width 画文本的区域的宽度 - * @param height 画文本的区域的高度 - * @param text 要画的文本 - * @param style 样式 - * @param resolution 屏幕分辨率 - */ - public static void drawStringStyleInRotation(Graphics2D g2d, int width, int height, String text, Style style, int resolution) { - if (StringUtils.isBlank(text)) { - return; - } - - Paint oldPaint = g2d.getPaint(); - Font oldFont = g2d.getFont(); - - if (style == null) { - style = Style.DEFAULT_STYLE; - } - - Font font = getStyleFont(g2d, style, resolution); - font = readExtraFont(g2d, font); - int horizontalAlignment = BaseUtils.getAlignment4Horizontal(style, text); - - if (style.getRotation() != 0 && style.getVerticalText() == Style.HORIZONTALTEXT) { - drawHorizontalText(g2d, text, font, style, width, height, horizontalAlignment); - } else { - drawRotationText(g2d, text, style, font, width, height, horizontalAlignment, resolution); - } - - g2d.setFont(oldFont); - g2d.setPaint(oldPaint); - } - - private static Font readExtraFont(Graphics2D g2d, Font font) { - ExtraClassManagerProvider pluginProvider = PluginModule.getAgent(PluginModule.ExtraCore); - if (pluginProvider != null) { - FontProcessor processor = pluginProvider.getSingle(FontProcessor.MARK_STRING); - if (processor != null) { - font = processor.readExtraFont(font); - g2d.setFont(font); - } - } - return font; - } - - private static void drawHorizontalText(Graphics2D g2d, String text, Font rfont, Style style, double width, double height, int horizontalAlignment) { - AffineTransform trans = new AffineTransform(); - trans.rotate(-Math.toRadians(style.getRotation())); - - double textX = width / 2.0; - double textY = height / 2.0; - - Dimension2D textDimension = GraphHelper.stringDimensionWithRotation(text, rfont, -style.getRotation(), g2d.getFontRenderContext()); - - if (textDimension.getWidth() < width) { - if (horizontalAlignment == Constants.LEFT) { - textX = textDimension.getWidth() / 2.0; - } else if (horizontalAlignment == Constants.RIGHT) { - textX = width - textDimension.getWidth() / 2.0 - style.getPaddingLeft() * - Math.cos(Math.toRadians(style.getRotation())); - } else { - } - } - - // adjust y, height. - if (textDimension.getHeight() < height) { - if (style.getVerticalAlignment() == Constants.TOP) { - textY = textDimension.getHeight() / 2.0; - } else if (style.getVerticalAlignment() == Constants.BOTTOM) { - textY = height - textDimension.getHeight() / 2.0 - style.getPaddingLeft() * Math.sin(Math.toRadians(style.getRotation())); - } else { - } - } - - GraphHelper.drawRotatedString(g2d, text, textX, textY, -style.getRotation()); - } - - private static void drawRotationText(Graphics2D g2d, String text, Style style, Font rfont, int width, int height, int horizontalAlignment, int resolution) { - AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess(); - if (process != null) { - process.drawRotationText(g2d, text, new ObjectHolder(style), rfont, width, height, horizontalAlignment, resolution); - return; - } - - FontMetrics cellFM = GraphHelper.getFontMetrics(rfont); - List lineTextList = BaseUtils.getLineTextList(text, style, rfont, height, width, resolution); - - if (width <= 0 || lineTextList.isEmpty()) { - return; - } - - int textAscent = cellFM.getAscent(); - int textHeight = cellFM.getHeight(); - - int textY = calculateTextY(style, height, textHeight, textAscent, lineTextList, resolution); - - int maxWidth = 0; - for (int i = 0; i < lineTextList.size(); i++) { - String paint_str = (String) lineTextList.get(i); - int textWidth = cellFM.stringWidth(paint_str); - if (textWidth > maxWidth) { - maxWidth = textWidth; - } - } - for (int i = 0; i < lineTextList.size(); i++) { - String paint_str = (String) lineTextList.get(i); - //把自定义角度为0的横排和竖排区分开来 - if (style.getRotation() == 0 && style.getVerticalText() == style.HORIZONTALTEXT) { - maxWidth = cellFM.stringWidth(paint_str); - } - boolean textLonger = false;//KevinWang: 标志一下:是否串长大于列宽 - if (maxWidth > width - style.getPaddingLeft() - style.getPaddingRight()) { - textLonger = true;//added by KevinWang <处理分散对齐时使用> - } //待会串长大于列宽时需要特别处理:只从中抽取合适长度的串值显示 - - int textX = (int) calculateTextX(style, width, maxWidth, horizontalAlignment, resolution); - int textWidth = width - style.getPaddingRight(); - if (isAutomaticLine(style, horizontalAlignment, textLonger)) {//自动换行时 - GraphHelper.drawString2(g2d, paint_str, textX, textY, textWidth); - } else if (isDistributeAlign(style, horizontalAlignment, textLonger)) { - drawTextWihenDistributeAlign(g2d, paint_str, cellFM, textWidth, textX, textY); - } else { //这里不能删除 - GraphHelper.drawString(g2d, paint_str, textX, textY); - } - textY += textHeight;// TODO 只增加了Y. - textY += PX.toPixWithResolution(style.getLineSpacing(), resolution); - } - } - - public static int calculateTextY(Style style, int height, int textHeight, int textAscent, List lineTextList, int resolution) { - return calculateTextY(style, height, textHeight, textAscent, lineTextList, resolution, 1); - } - - /** - * 计算Y的高度 - * - * @param style 样式 - * @param height 总高度 - * @param textHeight 文本高度 - * @param textAscent 字体的基线到大多数字母数字字符顶部的距离 - * @param lineTextList 文本列 - * @param resolution 分辨率 - * @return Y高度 - */ - public static int calculateTextY(Style style, int height, int textHeight, int textAscent, List lineTextList, int resolution, int scale) { - // 计算Y的高度. - int textY = 0; - int textAllHeight = textHeight * lineTextList.size(); - double spacingBefore = PX.toPixWithResolution(style.getSpacingBefore() * scale, resolution); - double spacingAfter = PX.toPixWithResolution(style.getSpacingAfter() * scale, resolution); - double lineSpacing = PX.toPixWithResolution(style.getLineSpacing() * scale, resolution); - textAllHeight += spacingBefore + spacingAfter + lineSpacing * lineTextList.size(); - if (style.getVerticalAlignment() == Constants.TOP) { - } else if (style.getVerticalAlignment() == Constants.CENTER) { - if (height > textAllHeight) {// 如果所有文本的高度小于当前可以绘区域的高度,就从0开始画字符. - textY = (height - textAllHeight) / 2; - } - } else if (style.getVerticalAlignment() == Constants.BOTTOM) { - if (height > textAllHeight) { - textY = height - textAllHeight; - } - } - textY += textAscent;// 在绘画的时候,必须添加Ascent的高度. - textY += spacingBefore + lineSpacing;//james:加上"段前间距"+“行间距” - return textY; - } - - - public static int calculateTextX(Style style, Font rfont, String paint_str, int width, int textWidth, int horizontalAlignment) { - return calculateTextX(style, rfont, paint_str, width, textWidth, horizontalAlignment, 1); - } - - /** - * 计算X宽度 - * - * @param style 样式 - * @param rfont 字体 - * @param paint_str 字符串 - * @param width 宽度 - * @param textWidth 文本宽度 - * @param horizontalAlignment 垂向对齐 - * @return X宽度 - */ - public static int calculateTextX(Style style, Font rfont, String paint_str, int width, int textWidth, int horizontalAlignment, int scale) { - int textX = style.getPaddingLeft() * scale; - if (horizontalAlignment == Constants.CENTER) { - textX += (width - textWidth - textX) / 2; - } else if (horizontalAlignment == Constants.RIGHT) { - textX = width - style.getPaddingRight() * scale - textWidth; -//// // TODO alex:just for flash print && for font.Tahoma -// if (Boolean.TRUE == FRCoreContext.TMAP.get() -// && ComparatorUtils.equals(rfont.getFontName(), "Tahoma")) { -// textX -= paint_str.length() / 3; -// } - } - return textX; - } - - /** - * 计算X宽度 - * - * @param style 样式 - * @param width 宽度 - * @param textWidth 文本宽度 - * @param horizontalAlignment 垂向对齐 - * @param resolution 分辨率 - * @return X宽度 - */ - public static double calculateTextX(Style style, int width, int textWidth, int horizontalAlignment, int resolution) { - return calculateTextX(style, width, textWidth, horizontalAlignment, resolution, 1); - } - - /** - * 计算文本X位置 - * - * @param style 样式 - * @param width 宽度 - * @param textWidth 文本宽度 - * @param horizontalAlignment 水平对齐 - * @return X宽度 - */ - public static double calculateTextX(Style style, int width, int textWidth, int horizontalAlignment, int resolution, int scale) { - double textX = padding2PixExcludeRight(style.getPaddingLeft(), resolution); - if (horizontalAlignment == Constants.CENTER) { - textX += (width - textWidth - textX) / 2f; - } else if (horizontalAlignment == Constants.RIGHT) { - textX = width - style.getPaddingRight() * scale - textWidth; - } - return textX; - } - - /** - * 将缩减、段间距转为对应dpi下的pix Ps:除了右缩进 - * - * @param padding - * @param resolution - * @return - */ - public static double padding2PixExcludeRight(int padding, int resolution) { - return PX.toPixWithResolution(padding, resolution); - } - - /** - * 将右缩进转为对应dpi下的pix - * - * @param paddingRight - * @param resolution - * @return - */ - public static double paddingRight2Pix(int paddingRight, int resolution) { - if (paddingRight == Style.DEFAULT_PADDING) { - return 0; - } - return paddingRight; - } - - public static boolean isAutomaticLine(Style style, int horizontalAlignment, boolean textLonger) { - return horizontalAlignment == Constants.DISTRIBUTED - && style.getTextStyle() == Style.TEXTSTYLE_WRAPTEXT - || horizontalAlignment == Constants.DISTRIBUTED - && style.getTextStyle() == Style.TEXTSTYLE_SINGLELINE - && !textLonger; - } - - public static boolean isDistributeAlign(Style style, int horizontalAlignment, boolean textLonger) { - return horizontalAlignment == Constants.DISTRIBUTED - && style.getTextStyle() == Style.TEXTSTYLE_SINGLELINE - && textLonger; - } - - public static void drawTextWihenDistributeAlign(Graphics2D g2d, String paint_str, FontMetrics cellFM, int width, int textX, int textY) { - drawTextWihenDistributeAlign(g2d, paint_str, cellFM, width, textX, textY, 1f); - } - - /** - * 画字符串:分散对齐 - * @param scale 缩放比例,主目前要用于删除线、下划线及阴影的绘制 - */ - public static void drawTextWihenDistributeAlign(Graphics2D g2d, String paint_str, FontMetrics cellFM, int width, int textX, int textY, float scale) { - String lineText = getSingleLineText(paint_str, cellFM, width); - if (StringUtils.isNotEmpty(lineText)) { - GraphDrawHelper.drawString4DistributeAlign(g2d, lineText, textX, textY, width, scale); - } - } - - /** - * 获取用于单行显示的text - * - * @param lineText 分行显示时第i行的内容,但是也可能单行 - * @param cellFM 字体 - * @param width 宽度 - * @return 拆分后的字符串 - */ - private static String getSingleLineText(String lineText, FontMetrics cellFM, int width) { - // 单行显示时的分散对齐实现e - // 串长大于列宽时需要特别处理:只从中抽取合适长度的串值显示 - StringBuffer strBuff = new StringBuffer(); - for (int charIndex = 0; charIndex < lineText.length(); charIndex++) { - strBuff.append(lineText.charAt(charIndex)); - int buffWidth = cellFM.stringWidth(new String(strBuff)); - if (buffWidth > width) { //长度足够了,开始显示 - return strBuff.substring(0, 0 == charIndex ? 0 : charIndex - 1);//只画一行 - } - } - //上面的width没有减去padding-left,可能啥也没画 - return strBuff.toString(); - } - - /** - * 将输入字符串转换为实际字符,\代表转义字符。 - * - * @param text 字符串 - * @return the real value 实际字符 - */ - public static String textToString(String text) { - //跟这里的drawText算法是一致的,这样"所见即所得", - //如果把drawText的参数text先用此方法转换也行的,但是会遍历俩次,所以先留着 - if (text == null) { - return ""; - } - - int len = text.length(); - StringBuffer sb = new StringBuffer(len); - - for (int i = 0; i < len; i++) { - char c = text.charAt(i); - if (c == '\\' && i + 1 < len) { - char next = text.charAt(i + 1); - if (next == 'n') { - i++; - c = '\n'; - } else if (next == '\\') { - i++; - } - - } - sb.append(c); - } - return sb.toString(); - } - - /** - * daniel: 自动换行算法, 这个算法要求跟DHTML中Table的自动换行表现结果一样 - * 所以统一72dpi进行处理 - * - * @param text - * @param style - * @param paintWidth - * @return - */ - public static List getLineTextList(String text, Style style, Font font, double paintWidth, int resolution) { - List lineTextList = new ArrayList(); - if (text == null || text.length() <= 0) { - return lineTextList; - } - - style = style == null ? Style.DEFAULT_STYLE : style; - - if (style.getRotation() != 0) { - lineTextList.add(text); - return lineTextList; - } - - if (style.getTextStyle() != Style.TEXTSTYLE_WRAPTEXT) { - return lineTextListNotChangeLine(lineTextList, text); - } - // 自动换行 - else { - UNIT width = FU.valueOfPix((int) paintWidth, resolution); - return lineTextListAutoChangeLine(lineTextList, text, font, style, width, resolution); - } - } - - private static List lineTextListNotChangeLine(List lineTextList, String text) { - char tmpChar; - StringBuffer tmpTextBuf = new StringBuffer(); - for (int t = 0; t < text.length(); t++) { - tmpChar = text.charAt(t); - if (tmpChar == '\\') {// 判断是否是 "\n" - if (t + 1 < text.length() && text.charAt(t + 1) == 'n') { - // 是"\n"字符串,但不是换行符. - t++; - lineTextList.add(tmpTextBuf.toString()); - tmpTextBuf.delete(0, tmpTextBuf.length()); - } else { - tmpTextBuf.append(tmpChar); - } - } else { - tmpTextBuf.append(tmpChar); - } - } - - // 最后一个 - if (tmpTextBuf.length() > 0) { - lineTextList.add(tmpTextBuf.toString()); - tmpTextBuf.delete(0, tmpTextBuf.length()); - } - - return lineTextList; - } - - /** - * 这里需要用resolution 72的dpi进行分行,因为96dpi会导致font有小数导致获取的宽度不正确 - * - * @param lineTextList - * @param text - * @param style - * @return - */ - private static List lineTextListAutoChangeLine(List lineTextList, String text, Font font, Style style, UNIT unitWidth, int resolution) { - - AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess(); - if (process != null) { - return process.autoChangeLine(text, new ObjectHolder(style), unitWidth); - } - if (font == null) { - font = style.getFRFont(); - } - FontMetrics fontMetrics = GraphHelper.getFontMetrics(font); - double paintWidth = unitWidth.toPixD(resolution); - double width = paintWidth - style.getPaddingLeft() - style.getPaddingRight() - style.getBorderLeftWidth(); - StringBuffer lineTextBuf = new StringBuffer(); - int lineTextWidth = 0; - - StringBuffer wordBuf = new StringBuffer(); - int wordWidth = 0; - int[] tmpWidth = new int[2]; - tmpWidth[0] = wordWidth; - tmpWidth[1] = lineTextWidth; - - lineTextListDealWithText(text, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics); - - // 最后处理 - if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) { - lineTextList.add(lineTextBuf.toString()); - lineTextList.add(wordBuf.toString()); - } else { - lineTextBuf.append(wordBuf); - lineTextList.add(lineTextBuf.toString()); - } - return lineTextList; - } - private static void lineTextListDealWithText(String text, List lineTextList, double width, int[] tmpWidth, - StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) { - for (int t = 0; t < text.length(); t++) { - if (t != 0 && isNumOrLetter(text.charAt(t)) && isNumOrLetter(text.charAt(t - 1))) { - dealWithTextNumOrLetter(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics); - } else if (text.charAt(t) == '\n' || (text.charAt(t) == '\r' && t + 1 < text.length() - 1 && text.charAt(t + 1) != '\n')) { - dealWithTextChangeLineSymbol(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics); - } else if (text.charAt(t) == '\\' && t + 1 < text.length() && text.charAt(t + 1) == 'n') {// 判断是否是 "\n" - // 是"\n"字符串,但不是换行符,依然需要换行. - dealWidthTextManualChangeLine(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics); - // 需要跳过后面的n - t++; - } else { - int increaseStep = 0; - if (text.charAt(t) == '\\' && t + 1 < text.length() && text.charAt(t + 1) == '\\') {// 判断是否是转义字符'\' - // _denny: 增加了转义字符'\\'用来表示\,使"\n"可以输入 - t++; - increaseStep++; - } - if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) { - if (isPunctuationAtLineHead(t, text)) { - for (int index = lineTextBuf.length(); index > 0; index--) { - char prec = lineTextBuf.charAt(index - 1); - lineTextBuf.deleteCharAt(index - 1); - if (!isPunctuation(prec)) { - break; - } - } - } - lineTextList.add(lineTextBuf.toString()); - lineTextBuf.delete(0, lineTextBuf.length()); - tmpWidth[1] = isPunctuationAtLineHead(t, text) ? dealWithPunctuationAtLinehead(t, fontMetrics, text, lineTextBuf, wordBuf.length(), increaseStep) : 0; - } - lineTextBuf.append(wordBuf); - tmpWidth[1] += tmpWidth[0]; - - wordBuf.delete(0, wordBuf.length()); - tmpWidth[0] = 0; - wordBuf.append(text.charAt(t)); - tmpWidth[0] = fontMetrics.charWidth(text.charAt(t)); - } - } - } - - - - /** - * 标点符号是否在换行后的行首 - */ - private static boolean isPunctuationAtLineHead(int t, String text) { - return t > 1 && BaseUtils.isPunctuation(text.charAt(t - 1)); - } - - private static int dealWithPunctuationAtLinehead(int t, FontMetrics fontMetrics, String text, StringBuffer lineTextBuf, int wordBufLength, int increaseStep) { - //lineTextBuf 最后一个字符下标 与 text当前字符下标 t 的距离 + 1 - int indexDistance = 1 + wordBufLength + increaseStep; - if (t < indexDistance) { - return 0; - } - int lineWidth = 0; - for (int index = t - indexDistance; index >= 0; index--) { - lineWidth += fontMetrics.charWidth(text.charAt(index)); - lineTextBuf.insert(0, text.charAt(index)); - if (!isPunctuation(text.charAt(index))) { - break; - } - } - return lineWidth; - } - - private static void dealWithTextNumOrLetter(String text, int t, List lineTextList, double width, int[] tmpWidth, - StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) { - if (tmpWidth[0] + fontMetrics.charWidth(text.charAt(t)) > width) { - if (tmpWidth[1] > 0) { - lineTextList.add(lineTextBuf.toString()); - lineTextBuf.delete(0, lineTextBuf.length()); - tmpWidth[1] = 0; - } - - lineTextList.add(wordBuf.toString()); - wordBuf.delete(0, wordBuf.length()); - tmpWidth[0] = 0; - } - - wordBuf.append(text.charAt(t)); - tmpWidth[0] += fontMetrics.charWidth(text.charAt(t)); - } - - private static void dealWithTextChangeLineSymbol(String text, int t, List lineTextList, double width, int[] tmpWidth, - StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) { - wordBuf.append('\n'); - if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) { - lineTextList.add(lineTextBuf.toString()); - lineTextList.add(wordBuf.toString()); - } else { - lineTextBuf.append(wordBuf); - lineTextList.add(lineTextBuf.toString()); - } - lineTextBuf.delete(0, lineTextBuf.length()); - tmpWidth[1] = 0; - wordBuf.delete(0, wordBuf.length()); - tmpWidth[0] = 0; - } - - private static void dealWidthTextManualChangeLine(String text, int t, List lineTextList, double width, int[] tmpWidth, - StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) { - t++;// 忽略'n'字符. - wordBuf.append('\n'); - if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) { - lineTextList.add(lineTextBuf.toString()); - lineTextList.add(wordBuf.toString()); - } else { - lineTextBuf.append(wordBuf); - lineTextList.add(lineTextBuf.toString()); - } - lineTextBuf.delete(0, lineTextBuf.length()); - tmpWidth[1] = 0; - wordBuf.delete(0, wordBuf.length()); - tmpWidth[0] = 0; - } - - - /** - * @param cuChar - * @return - * @see StableUtils - * @deprecated - */ - public static boolean isNum(char cuChar) { - return StableUtils.isNum(cuChar); - } - - - /** - * 判断字符是否为数字或字母 - * - * @param curChar 被检查的字符 - * @return 是否为数字或字母 - */ - public static boolean isNumOrLetter(char curChar) { - return GeneralUtils.isLetter(curChar) || StableUtils.isNum(curChar); - } - - public static boolean isPunctuation(char c) { - int type = Character.getType(c); - return type == Character.OTHER_PUNCTUATION - || type == Character.DASH_PUNCTUATION - || type == Character.START_PUNCTUATION - || type == Character.END_PUNCTUATION - || type == Character.CONNECTOR_PUNCTUATION; - } - - - public static List getLineTextList(String text, Style style, Font font, double paintHeight, double paintWidth) { - return getLineTextList(text, style, font, paintHeight, paintWidth, Constants.DEFAULT_PRINT_AND_EXPORT_RESOLUTION); - } - - /** - * james daniel 放一起 - * 同时含有height和width参数表示会根据style自动判断字体为竖排还是横排 - * TODO - */ - public static List getLineTextList(String text, Style style, Font font, double paintHeight, double paintWidth, int resolution) { - //正常文字 - if (style == null - || style.getVerticalText() != Style.VERTICALTEXT) {//james:正常的文字时 - return BaseUtils.getLineTextList(text, style, font, paintWidth, resolution); - } - ExtraClassManagerProvider pluginProvider = PluginModule.getAgent(PluginModule.ExtraCore); - if (pluginProvider != null) { - VerticalTextProcessor processor = pluginProvider.getSingle(VerticalTextProcessor.XML_TAG, DefaultVerticalTextProcessor.class); - String[] res = processor.process(text, style, font, paintHeight, paintWidth, resolution); - return Arrays.asList(res); - } - String[] res = new DefaultVerticalTextProcessor().process(text, style, font, paintHeight, paintWidth, resolution); - return Arrays.asList(res); - } - - /** - * 返回边框宽 - * - * @param borderType 边框类型 - * @return 宽度 - */ - public static int getBorderWidth(int borderType) { - switch (borderType) { - case Constants.LINE_NONE: - return 0; - case Constants.LINE_SLIM: - return 1; - case Constants.LINE_THIN: - return 1; - case Constants.LINE_DASH: - return 1; - case Constants.LINE_HAIR: - return 1; - case Constants.LINE_HAIR2: - return 1; - case Constants.LINE_THICK: - return 3; - case Constants.LINE_DOT: - return 1; - default: - return 2; - } - } - - /** - * 将边框转为对应的字符串描述 - * - * @param borderStyle 边框线型 - * @return web端对应的边框 - */ - public static String border2Style(int borderStyle) { - switch (borderStyle) { - case Constants.LINE_NONE: - return "none"; - case Constants.LINE_SLIM: - return "solid"; - case Constants.LINE_THIN: - return "solid"; - case Constants.LINE_MEDIUM: - return "solid"; - case Constants.LINE_THICK: - return "solid"; - case Constants.LINE_DOUBLE: - return "double"; - case Constants.LINE_DOT: - return "double"; - case Constants.LINE_DASH_DOT: - return "double"; - case Constants.LINE_DASH_DOT_DOT: - return "dotted"; - default: - return "dashed"; - } - } - - /** - * 克隆对象 - * - * @param object 对象 - * @return 克隆出的对象 - * @throws CloneNotSupportedException 不被支持的克隆异常 - * @see StableUtils#cloneObject(Object) - * @deprecated - */ - public static Object cloneObject(Object object) throws CloneNotSupportedException { - return StableUtils.cloneObject(object); - } - - - /** - * 把java.util.Map转成一段JSONObject的String与上面方法对应 - * - * @param map map对象 - * @return json对象 - * @throws JSONException json异常 - */ - public static JSONObject map2JSON(Map map) throws JSONException { - JSONObject jo = new JSONObject(); - Iterator iter = map.keySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - Object value = entry.getValue(); - if (value instanceof FArray) { - JSONArray ja = new JSONArray(); - FArray array = (FArray) value; - for (int i = 0; i < array.length(); i++) { - ja.put(array.elementAt(i)); - } - value = ja; - } - jo.put((String) entry.getKey(), value); - } - return jo; - } - - /** - * 将一个对象转化成json样式的字符串 - * - * @param o 待转化的对象 - * @return json样式的字符串 - * @throws JSONException json异常 - * @see EmbedJson#encode(Object) (Object) - * @deprecated - */ - public static String jsonEncode(Object o) throws JSONException { - return EmbedJson.encode(o); - } - - - /** - * 将一个字符串转化成JSON格式的对象 - * - * @param str 要转化的字符串 - * @return JSON格式的对象 - * @throws JSONException json异常 - * @see JSONUtils#jsonDecode(String) - * @deprecated - */ - public static Object jsonDecode(String str) throws JSONException { - return JSONUtils.jsonDecode(str); - } - - /** - * 检查图片1和2是否相同. - * - * @param img1 图片1 - * @param img2 图片2 - * @return 图片1和2是否相同 - */ - public static boolean imageEquals(Image img1, Image img2) { - if (img1 == img2) { - return true; - } - - if (img1 == null || img2 == null) {//null < not null - return img1 == null && img2 == null; - } - - //开始比较图片. - byte[] buf1 = GeneralXMLTools.imageEncode(img1); - byte[] buf2 = GeneralXMLTools.imageEncode(img2); - if (buf1.length != buf2.length) { - return false; - } - - for (int i = 0; i < buf1.length; i++) { - if (buf1[i] != buf2[i]) { - return false; - } - } - - return true; - } - - /** - * 根据数据集名获取数据模型 - * - * @param cal 算子 - * @param tdName 列表名 - * @return 数据模型 - */ - public static DataModel getDataModelFromTableDataName(Calculator cal, String tdName) { - String tableDataName = tdName; - //先看当前的报表中的私有数据源 - DataModel resultSet = SynchronizedLiveDataModelUtils.getSELiveDataModel4Share(cal, tableDataName); - if (resultSet == null) { - TableData td = TableDataAssist.getTableData(cal, tableDataName); - resultSet = td == null ? null : td.createDataModel(cal); - } - return resultSet; - } - - - /** - * kunsnat: List转化为二维表 - * - * @param list 列表 - * @return 二维数组 - */ - public static Object[][] list2Array2D(List list) { - int rowNum = list.size(); - int colNum = 0; - for (int i = 0; i < rowNum; i++) { - List row = (List) list.get(i); - if (row.size() > colNum) { - colNum = row.size(); - } - } - Object[][] result = new Object[rowNum][colNum]; - - for (int i = 0; i < rowNum; i++) { - List row = (List) list.get(i); - for (int j = 0; j < colNum; j++) { - if (j < row.size()) { - result[i][j] = row.get(j); - } else { - result[i][j] = null; - } - } - } - - return result; - } - - /** - * 判断当前Env下是否有lic文件 - * - * @return 判断当前Env下是否有lic文件 - */ - public static boolean checkLicExist() { - - if (ServerPreferenceConfig.getInstance().isLicUseLock()) { - return true;//加密狗 - } else if (!LicenseConfigManager.getInstance().isUseFile()) { - //不使用文件,说明用户配置了注册信息,一定是注册了 - return true; - } - - try { - String licName = FRContext.getCommonOperator().getLicenseName(); - byte[] bytes = WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.RESOURCES_NAME, licName)); - return bytes != null && bytes.length != 0; - } catch (Exception ignored) { - } - - return false; - } - - /** - * 判断是否内容为图表相关. - * - * @param cellOption 单元格属性 - * @return 返回是否为图表单元格相关. - */ - public static boolean isChartCell(JSONObject cellOption) { - if (cellOption != null) { - JSONObject value = cellOption.optJSONObject("value"); - if (value != null) { - return ComparatorUtils.equals("simplechart", value.optString("type")); - } - } - - return false; - } -} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java b/designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java index 6bebbbbe8..1d3c85f2c 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/LayoutTool.java @@ -7,20 +7,16 @@ import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.fit.NewJForm; -import com.fr.design.mainframe.FormArea; import com.fr.design.mainframe.JForm; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.container.WAbsoluteBodyLayout; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WLayout; import com.fr.form.ui.widget.CRBoundsWidget; -import com.fr.general.FRScreen; import com.fr.log.FineLoggerFactory; import java.awt.Component; -import java.awt.Dimension; import java.awt.Rectangle; -import java.awt.Toolkit; /** * @description:布局工具类 @@ -163,15 +159,4 @@ public class LayoutTool { } } - /** - * @Description: 获取老预览时的缩放比例 - * @return: - * @Author: Henry.Wang - * @date: 2020/10/26 20:39 - */ - public static double getContainerPercent(){ - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - double screenValue = FRScreen.getFRScreenByDimension(screen).getValue(); - return screenValue / FormArea.DEFAULT_SLIDER; - } } diff --git a/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java b/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java deleted file mode 100644 index a937ba2d4..000000000 --- a/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java +++ /dev/null @@ -1,2030 +0,0 @@ -/* - * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. - */ -package com.fr.design.fit.common; - -import com.fr.base.BaseFormula; -import com.fr.base.CoreDecimalFormat; -import com.fr.base.FRContext; -import com.fr.base.FormatRepository; -import com.fr.base.GraphHelper; -import com.fr.base.ImageProvider; -import com.fr.base.Painter; -import com.fr.base.Style; -import com.fr.base.Utils; -import com.fr.base.background.ImageBackground; -import com.fr.common.annotations.Open; -import com.fr.data.DataBaseUtils; -import com.fr.general.Background; -import com.fr.general.ComparatorUtils; -import com.fr.general.DateUtils; -import com.fr.general.DefaultValues; -import com.fr.general.FRFont; -import com.fr.general.GeneralUtils; -import com.fr.json.JSONException; -import com.fr.json.JSONObject; -import com.fr.stable.AssistUtils; -import com.fr.stable.Constants; -import com.fr.stable.CoreGraphHelper; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; -import com.fr.stable.unit.PT; -import com.fr.stable.web.Repository; -import com.fr.stable.web.ServletContext; -import com.fr.stable.web.ServletContextAdapter; -import org.jetbrains.annotations.Nullable; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Paint; -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.geom.Rectangle2D; -import java.io.InvalidObjectException; -import java.io.Serializable; -import java.sql.Clob; -import java.text.DateFormat; -import java.text.Format; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 用于表示样式的类,包括边框、颜色、字体、缩进、间距等 - * 注意:这是一个开放类,所有的修改都要注意保持兼容 - */ -@Open -public class NewFormStyle extends Style implements Serializable, Cloneable { - - // temp rectangle - private static Rectangle2D tempRectangle2D = new Rectangle2D.Double(0, 0, 0, 0); - - public static final int TEXTSTYLE_WRAPTEXT = 0; // 换行. - public static final int TEXTSTYLE_SINGLELINE = 1; // 单行,超出部分不显示. - public static final int TEXTSTYLE_SINGLELINEADJUSTFONT = 2; // 单行,调整字体来显示所有的字. - public static final int TEXTSTYLE_MULTILINEADJUSTFONT = 3; //多行,固定单元格高和宽,调整字体来显示所有的字 - - public static final int VERTICALTEXT = 1;// 竖排,与Excel中的设置值相同 - public static final int HORIZONTALTEXT = 0;// 横排 - - public static final int LEFT_TO_RIGHT = 1;// JAMES:垂直文字时,文字为从左向右顺序排列 - public static final int RIGHT_TO_LEFT = 0;// JAMES:垂直文字时,文字为从右向左顺序排列 - - //EXCEL 宋体11号字, 一个缩进单位对应96dpi下27px - public static final int PADDING_ARG = 27; - public static final int DEFAULT_PADDING = 2; - /** - * 细线透明度值 - */ - public static final double FACTORY_ALPHA = 0.4; - public static final NewFormStyle NULL_STYLE = null; - - /** - * Default Style - */ - public static final NewFormStyle DEFAULT_STYLE = new NewFormStyle(); - - /** - * Border Style - */ - public static final NewFormStyle BORDER_STYLE = new NewFormStyle(); - - private static final long serialVersionUID = -1675056857456167839L; - private static final int MAX_FONT_SIZE = 100; - private static final int N_SIZE = 9; - private static final int MIN_SIZE = 8; - private static final int MAX_SIZE = 26; - - private static final int LINE_HEIGHT_FIX = 4; - private static final int LINE_HEIGHT_FIX2 = 3; - - private static class ContentLineGroup { - Style style; - List newLineTextList; - int newTextHeight; - - public ContentLineGroup(Style style, List lineList, int textHeight) { - this.style = style; - this.newLineTextList = lineList; - this.newTextHeight = textHeight; - } - - public int totalHeight() { - return newTextHeight * newLineTextList.size(); - } - } - - private static Map clsFontFamily = null; - - // 全局Style的map - private static Map initializeStyle = new ConcurrentHashMap();// - - static { - ServletContext.addServletContextListener(new ServletContextAdapter() { - @Override - public void onServletStop() { - initializeStyle.clear(); - } - }); - } - - // format - private Format format = null; - - // element font. - private FRFont frFont = null; - - private Background background = null; - - // border. - private byte border_top = Constants.LINE_NONE; - private byte border_left = Constants.LINE_NONE; - private byte border_bottom = Constants.LINE_NONE; - private byte border_right = Constants.LINE_NONE; - private Color border_top_color = Color.BLACK; - private Color border_left_color = Color.BLACK; - private Color border_bottom_color = Color.BLACK; - private Color border_right_color = Color.BLACK; - - // alignment. - private int horizontal_alignment = Constants.NULL; - private int vertical_alignment = Constants.CENTER; - - // TextStyle - private int textStyle = NewFormStyle.TEXTSTYLE_WRAPTEXT; - - // james: verticalText - private int verticalText = NewFormStyle.HORIZONTALTEXT;// 默认为0,水平方向 - - // james: the direction of text when the text is vertical - private int textDirection = NewFormStyle.RIGHT_TO_LEFT;// 默认为从右向左的顺序 - - private int rotation = 0; - - private byte imageLayout = Constants.IMAGE_CENTER;//现在默认改为center了 - - //padding有两个计量单位, 一种是以前的pt, 一种是现在的, 为了兼容excel的 - //设计器中设置1个单位, 兼容为以前的27pt - // 左缩进 - private int paddingLeft = DEFAULT_PADDING; - // 右缩进 - private int paddingRight = DEFAULT_PADDING; - - // 段前间距 - private byte spacingBefore = 0; - // 段后间距 - private byte spacingAfter = 0; - // 行间距h - private byte lineSpacing = 0; - - private String contentClsCss = StringUtils.EMPTY; - private Map contentStyleCssMap = new HashMap(); - - private String borderClsCss = StringUtils.EMPTY; - private Map borderStyleCssMap = new HashMap(); - - /** - * Constructor. - */ - protected NewFormStyle() { - //peter:这里主动从Context, 获得默认的FRFont的值. - DefaultValues defaultValues = FRContext.getDefaultValues(); - this.frFont = defaultValues.getFRFont(); - - // HTML输出 CSS初始化 - this.contentClsCss = this.contentStyle2class(this.contentStyleCssMap); - this.borderClsCss = this.border2Class(this.borderStyleCssMap); - } - - private NewFormStyle(Background background, Format format, FRFont frFont, - int border_top, Color border_top_color, int border_bottom, Color border_bottom_color, - int border_left, Color border_left_color, int border_right, Color border_right_color, - int horizontal_alignment, int vertical_alignment, int textStyle, - int verticalText, int textDirection, int rotation, int imageLayout, - int paddingLeft, int paddingRight, int spacingBefore, int spacingAfter, int lineSpacing) { - this.background = background; - this.format = format; - this.frFont = frFont; - - this.border_top = (byte) border_top; - this.border_top_color = border_top_color; - this.border_bottom = (byte) border_bottom; - this.border_bottom_color = border_bottom_color; - this.border_left = (byte) border_left; - this.border_left_color = border_left_color; - this.border_right = (byte) border_right; - this.border_right_color = border_right_color; - - this.horizontal_alignment = (byte) horizontal_alignment; - this.vertical_alignment = (byte) vertical_alignment; - this.textStyle = (byte) textStyle; - - this.verticalText = (byte) verticalText; - this.textDirection = (byte) textDirection; - this.rotation = (short) rotation; - this.imageLayout = (byte) imageLayout; - - this.paddingLeft = paddingLeft; - this.paddingRight = paddingRight; - - this.spacingBefore = (byte) spacingBefore; - this.spacingAfter = (byte) spacingAfter; - this.lineSpacing = (byte) lineSpacing; - - // HTML输出 CSS初始化 - this.contentClsCss = this.contentStyle2class(this.contentStyleCssMap); - this.borderClsCss = this.border2Class(this.borderStyleCssMap); - } - - private static Map getclsFontFamily() { - if (clsFontFamily == null) { - clsFontFamily = new HashMap() { - { - put("Arial Black", "fnab"); - put("Basic Sans SF", "fnbs"); - put("Book Antiqua", "fnba"); - put("Calibri", "fnci"); - put("Comic Sans MS", "fncs"); - put("Courier New", "fncn"); - put("Elementary SF", "fnes"); - put("Garamond", "fngd"); - put("Georgia", "fnga"); - put("Letter Gothic", "fnlg"); - put("Lucida Console", "fnlc"); - put("Marigold", "fnmd"); - put("MS Sans Serif", "fnms"); - put("MS Gothic", "fnmg"); - put("MS PGothic", "fnmpg"); - put("MS Mincho", "fnmm"); - put("MS P Mincho", "fnmpm"); - put("MingLiU", "fnml"); - put("SimHei", "fnsh"); - put("System", "fnsm"); - put("Tahoma", "fnta"); - put("Times New Roman", "fntn"); - put("Trebuchet MS", "fntms"); - put("Verdana", "fnva"); - - put("SimSun", "fnss"); - put("Arial", "fnar"); - put("Microsoft YaHei", "fnyh"); - put("KaiTi", "fnkt"); - } - }; - } - - return clsFontFamily; - } - - /** - * 设置样式 - * - * @param format 格式g - * @return 样式y - */ - public NewFormStyle deriveFormat(Format format) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 获取实例 - */ - public static NewFormStyle getInstance(Format format) { - return DEFAULT_STYLE.deriveFormat(format); - } - - /** - * 设置字体 - * - * @param frFont 字体 - * @return 样式 - */ - public NewFormStyle deriveFRFont(FRFont frFont) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * getInstance - */ - public static NewFormStyle getInstance() { - NewFormStyle style = new NewFormStyle(); - - Object valueStyle = initializeStyle.get(style); - if (valueStyle != null) { - return (NewFormStyle) valueStyle; - } else { - initializeStyle.put(style, style); - return style; - } - } - - /** - * getInstance - */ - private static NewFormStyle getInstance(Background background, Format format, FRFont frFont, - int border_top, Color border_top_color, int border_bottom, Color border_bottom_color, - int border_left, Color border_left_color, int border_right, Color border_right_color, - int horizontal_alignment, int vertical_alignment, int textStyle, - int verticalText, int textDirection, int rotation, int imageLayout, - int paddingLeft, int paddingRight, int spacingBefore, int spacingAfter, int lineSpacing) { - NewFormStyle style = new NewFormStyle(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - - Object valueStyle = initializeStyle.get(style); - if (valueStyle != null) { - return (NewFormStyle) valueStyle; - } else { - initializeStyle.put(style, style); - return style; - } - } - - /** - * getInstance - */ - public static NewFormStyle getInstance(FRFont frFont) { - if (frFont == null) { - return NewFormStyle.getInstance(); - } - return DEFAULT_STYLE.deriveFRFont(frFont); - } - - /** - * 设置背景 - * - * @param background 背景 b - * @return 样式 y - */ - public NewFormStyle deriveBackground(Background background) { - if (background instanceof ImageBackground) { - return new NewFormStyle(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * getInstance - */ - public static NewFormStyle getInstance(Background background) { - return DEFAULT_STYLE.deriveBackground(background); - } - - /** - * 去掉边框和单元格背景 - * - * @return 样式y - */ - public NewFormStyle deriveBorderBackgroundNone() { - return getInstance(null, format, frFont, - Constants.LINE_NONE, border_top_color, Constants.LINE_NONE, border_bottom_color, - Constants.LINE_NONE, border_left_color, Constants.LINE_NONE, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置边框 - * - * @param border_top 上边框像素 - * @param border_top_color 上边框颜色s - * @param border_bottom 下 x - * @param border_bottom_color 下 x - * @param border_left 左 z - * @param border_left_color 左z - * @param border_right 右y - * @param border_right_color 右y - * @return 样式y - */ - public NewFormStyle deriveBorder(int border_top, Color border_top_color, - int border_bottom, Color border_bottom_color, - int border_left, Color border_left_color, - int border_right, Color border_right_color) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置上边框 - * - * @param border_top 上边框尺寸s - * @param border_top_color 上边框颜色 s - * @return 样式 y - */ - public NewFormStyle deriveBorderTop(int border_top, Color border_top_color) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置下边框 - * - * @param border_bottom 下边框尺寸 x - * @param border_bottom_color 下颜色x - * @return 样式y - */ - public NewFormStyle deriveBorderBottom(int border_bottom, Color border_bottom_color) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置左边框 - * - * @param border_left 尺寸 z - * @param border_left_color 颜色y - * @return 样式y - */ - public NewFormStyle deriveBorderLeft(int border_left, Color border_left_color) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置右边框 - * - * @param border_right 尺寸 c - * @param border_right_color 颜色 y - * @return 样式 y - */ - public NewFormStyle deriveBorderRight(int border_right, Color border_right_color) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置水平方向 - * - * @param horizontal_alignment 水平方向s - * @return 样式 y - */ - public NewFormStyle deriveHorizontalAlignment(int horizontal_alignment) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置垂直方向 - * - * @param vertical_alignment 垂直方向c - * @return 样式 - * @see Constants#TOP - * @see Constants#CENTER - * @see Constants#BOTTOM - */ - public NewFormStyle deriveVerticalAlignment(int vertical_alignment) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置单元格展示样式(自动换行, 单行显示, 多行显示等) - * - * @param textStyle 文字样式 - * @return 样式 - * @see NewFormStyle#TEXTSTYLE_WRAPTEXT - * @see NewFormStyle#TEXTSTYLE_SINGLELINE - * @see NewFormStyle#TEXTSTYLE_SINGLELINEADJUSTFONT - * @see NewFormStyle#TEXTSTYLE_MULTILINEADJUSTFONT - */ - public NewFormStyle deriveTextStyle(int textStyle) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置单元格方向 - * - * @param textDirection 文本方向w - * @return 样式t - */ - public NewFormStyle deriveTextDirection(int textDirection) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置单元格垂直方向 - * - * @param verticalText 垂直方向c - * @return 样式 - */ - public NewFormStyle deriveVerticalText(int verticalText) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置旋转方向 - * - * @param rotation 旋转方向 the new rotation of cell (between -90 and 90 degrees). - * @return 样式 - */ - public NewFormStyle deriveRotation(int rotation) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置图片布局 - * - * @param imageLayout the new image layout 图片布局t - * @return 样式 - * @see Constants#IMAGE_TILED - * @see Constants#IMAGE_CENTER - * @see Constants#IMAGE_EXTEND - */ - public NewFormStyle deriveImageLayout(int imageLayout) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置缩进 - * - * @param paddingLeft 左缩进 - * @param paddingRight 右缩进 - * @return 样式 - */ - public NewFormStyle derivePadding(int paddingLeft, int paddingRight) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置左缩进 - * - * @param paddingLeft 左缩进 - * @return 样式 - */ - public NewFormStyle derivePaddingLeft(int paddingLeft) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置右缩进 - * - * @param paddingRight 右缩进 - * @return 样式 - */ - public NewFormStyle derivePaddingRight(int paddingRight) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置段前间距 - * - * @param spacingBefore 段前间距d - * @return 样式 y - */ - public NewFormStyle deriveSpacingBefore(int spacingBefore) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置段后间距 - * - * @param spacingAfter 段后间距d - * @return 样式y - */ - public NewFormStyle deriveSpacingAfter(int spacingAfter) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 设置行间距 - * - * @param lineSpacing 行间距h - * @return 样式y - */ - public NewFormStyle deriveLineSpacing(int lineSpacing) { - return getInstance(background, format, frFont, - border_top, border_top_color, border_bottom, border_bottom_color, - border_left, border_left_color, border_right, border_right_color, - horizontal_alignment, vertical_alignment, textStyle, - verticalText, textDirection, rotation, imageLayout, - paddingLeft, paddingRight, spacingBefore, spacingAfter, lineSpacing); - } - - /** - * 对象转为json格式 - * - * @param repo 浏览器上下文 - * @param size 单元格大小 - * @return json格式数据 - */ - public JSONObject toJSONObject(Repository repo, Dimension size) throws JSONException { - JSONObject jo = new JSONObject(); - if (background != null) { - jo.put("background", background.toJSONObject(repo, size)); - } - // 不是默认值才输出,节省流量 - if (frFont != null && !ComparatorUtils.equals(frFont, FRContext.getDefaultValues().getFRFont())) { - jo.put("font", frFont.toJSONObject(repo)); - } - - if (!checkLeftRightTopBottom4b0()) { - jo.put("border", border2JSONObject()); - jo.put("borderCss", borderClsCss); - } - - createAlignAndTextStyleConfig(jo); - if (rotation != 0) { - jo.put("ro", rotation); - } - if (imageLayout != Constants.IMAGE_CENTER) { - jo.put("il", imageLayout); - } - createSpacingAndPaddingConfig(jo); - - return jo; - } - - private void createAlignAndTextStyleConfig(JSONObject jo) throws JSONException { - if (horizontal_alignment != Constants.NULL) { - jo.put("ha", horizontal_alignment); - } - if (vertical_alignment != Constants.CENTER) { - jo.put("va", vertical_alignment); - } - if (textStyle != TEXTSTYLE_WRAPTEXT) { - jo.put("ts", textStyle); - } - if (verticalText != NewFormStyle.HORIZONTALTEXT) { - jo.put("vt", verticalText); - } - if (textDirection != RIGHT_TO_LEFT) { - jo.put("td", textDirection); - } - jo.put("contentCss", contentClsCss); - } - - private void createSpacingAndPaddingConfig(JSONObject jo) throws JSONException { - if (paddingLeft != DEFAULT_PADDING) { - jo.put("pl", paddingLeft); - } - if (paddingRight != DEFAULT_PADDING) { - jo.put("pr", paddingRight); - } - if (spacingBefore != 0) { - jo.put("sb", spacingBefore); - } - if (spacingAfter != 0) { - jo.put("sa", spacingAfter); - } - if (lineSpacing != 0) { - jo.put("ls", lineSpacing); - } - } - - /** - * 获取字体 - */ - public FRFont getFRFont() { - if (this.frFont == null) { - this.frFont = FRContext.getDefaultValues().getFRFont(); - } - return this.frFont; - } - - /** - * Gets cell format. - */ - public Format getFormat() { - return this.format; - } - - /** - * Gets background. - */ - public Background getBackground() { - return this.background; - } - - /** - * Gets the type of border to use for the top border of the cell. - * - * @see Constants#LINE_NONE - * @see Constants#LINE_THIN - * @see Constants#LINE_MEDIUM - * @see Constants#LINE_DASH - * @see Constants#LINE_HAIR - * @see Constants#LINE_HAIR2 - * @see Constants#LINE_THICK - * @see Constants#LINE_DOUBLE - * @see Constants#LINE_DOT - * @see Constants#LINE_MEDIUM_DASH - * @see Constants#LINE_DASH_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT - * @see Constants#LINE_DASH_DOT_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT_DOT - * @see Constants#LINE_SLANTED_DASH_DOT - */ - public int getBorderTop() { - return this.border_top; - } - - /** - * 获取上边框线的宽度 - */ - public int getBorderTopWidth() { - return GraphHelper.getLineStyleSize(this.getBorderTop()); - } - - /** - * Gets the type of border to use for the left border of the cell. - * - * @see Constants#LINE_NONE - * @see Constants#LINE_THIN - * @see Constants#LINE_MEDIUM - * @see Constants#LINE_DASH - * @see Constants#LINE_HAIR - * @see Constants#LINE_HAIR2 - * @see Constants#LINE_THICK - * @see Constants#LINE_DOUBLE - * @see Constants#LINE_DOT - * @see Constants#LINE_MEDIUM_DASH - * @see Constants#LINE_DASH_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT - * @see Constants#LINE_DASH_DOT_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT_DOT - * @see Constants#LINE_SLANTED_DASH_DOT - */ - public int getBorderLeft() { - return this.border_left; - } - - public int getBorderLeftWidth() { - return GraphHelper.getLineStyleSize(this.getBorderLeft()); - } - - public int getBorderRightWidth() { - return GraphHelper.getLineStyleSize(this.getBorderRight()); - } - - public int getBorderBottomWidth() { - return GraphHelper.getLineStyleSize(this.getBorderBottom()); - } - - /** - * Gets the type of border to use for the bottom border of the cell. - * - * @see Constants#LINE_NONE - * @see Constants#LINE_THIN - * @see Constants#LINE_MEDIUM - * @see Constants#LINE_DASH - * @see Constants#LINE_HAIR - * @see Constants#LINE_HAIR2 - * @see Constants#LINE_THICK - * @see Constants#LINE_DOUBLE - * @see Constants#LINE_DOT - * @see Constants#LINE_MEDIUM_DASH - * @see Constants#LINE_DASH_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT - * @see Constants#LINE_DASH_DOT_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT_DOT - * @see Constants#LINE_SLANTED_DASH_DOT - */ - public int getBorderBottom() { - return this.border_bottom; - } - - /** - * Gets the type of border to use for the right border of the cell. - * - * @see Constants#LINE_NONE - * @see Constants#LINE_THIN - * @see Constants#LINE_MEDIUM - * @see Constants#LINE_DASH - * @see Constants#LINE_HAIR - * @see Constants#LINE_HAIR2 - * @see Constants#LINE_THICK - * @see Constants#LINE_DOUBLE - * @see Constants#LINE_DOT - * @see Constants#LINE_MEDIUM_DASH - * @see Constants#LINE_DASH_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT - * @see Constants#LINE_DASH_DOT_DOT - * @see Constants#LINE_MEDIUM_DASH_DOT_DOT - * @see Constants#LINE_SLANTED_DASH_DOT - */ - public int getBorderRight() { - return this.border_right; - } - - /** - * Gets the color of border to use for the top border of the cell. - */ - public Color getBorderTopColor() { - return this.border_top_color; - } - - /** - * Gets the color of border to use for the left border of the cell. - */ - public Color getBorderLeftColor() { - return this.border_left_color; - } - - /** - * Gets the color of border to use for the bottom border of the cell. - */ - public Color getBorderBottomColor() { - return this.border_bottom_color; - } - - /** - * Gets the color of border to use for the right border of the cell. - */ - public Color getBorderRightColor() { - return this.border_right_color; - } - - /** - * Gets the type of horizontal alignment for the cell - * - * @see BaseUtils#getAlignment4Horizontal(NewFormStyle style, Object value) - * @see BaseUtils#getAlignment4Horizontal(NewFormStyle style) - * @see Constants#LEFT - * @see Constants#CENTER - * @see Constants#RIGHT - * @deprecated suggest not directly use; - */ - public int getHorizontalAlignment() { - return this.horizontal_alignment; - } - - /** - * Gets the type of vertical alignment for the cell - * - * @see Constants#TOP - * @see Constants#CENTER - * @see Constants#BOTTOM - */ - public int getVerticalAlignment() { - return this.vertical_alignment; - } - - /** - * Gets the text style. - * - * @see NewFormStyle#TEXTSTYLE_WRAPTEXT - * @see NewFormStyle#TEXTSTYLE_SINGLELINE - * @see NewFormStyle#TEXTSTYLE_SINGLELINEADJUSTFONT - * @see NewFormStyle#TEXTSTYLE_MULTILINEADJUSTFONT - */ - public int getTextStyle() { - return textStyle; - } - - /** - * Gets the value of verticalText - */ - public int getVerticalText() { - return this.verticalText; - } - - /** - * Gets the value of textDirection - */ - public int getTextDirection() { - return this.textDirection; - } - - /** - * Gets the degree of rotation for the text in the cell - * (between -90 and 90 degrees). - */ - public int getRotation() { - return this.rotation; - } - - /** - * Gets the image layout - * - * @return the image layout - * @see Constants#IMAGE_TILED - * @see Constants#IMAGE_CENTER - * @see Constants#IMAGE_EXTEND - */ - public int getImageLayout() { - return imageLayout; - } - - /** - * get indentation value - */ - public int getPaddingLeft() { - return this.paddingLeft; - } - - /** - * get indentation value - */ - public int getPaddingRight() { - return this.paddingRight; - } - - /** - * @return the spacingBefore - */ - public byte getSpacingBefore() { - return spacingBefore; - } - - /** - * @return the spacingAfter - */ - public byte getSpacingAfter() { - return spacingAfter; - } - - /** - * @return the lineSpacing - */ - public byte getLineSpacing() { - return lineSpacing; - } - - - /** - * 如果单元格内容不为数字或者字符串的时候使用静态数据 - * - * @return - */ - public String getContentClsCss() { - return contentClsCss; - } - - /** - * 若value为数字或字符串需要判断一下是否可以转换为数字显示 - * - * @param value - * @return - */ - public String getContentClsCss(Object value) { - return this.contentStyle2class(this.contentStyleCssMap, value); - } - - /** - * getContentStyleCssMap - */ - public Map getContentStyleCssMap() { - return contentStyleCssMap; - } - - /** - * getBorderClsCss - */ - public String getBorderClsCss() { - return borderClsCss; - } - - /** - * getBorderStyleCssMap - */ - public Map getBorderStyleCssMap() { - return borderStyleCssMap; - } - - /** - * contentStyle2class - */ - private String contentStyle2class(Map contentCssMap) { - return contentStyle2class(contentCssMap, null); - } - - protected String contentStyle2class(Map contentCssMap, Object value) { - StringBuilder sb = new StringBuilder(); - sb.append("fh"); - int horizontal_alignment = BaseUtils.getAlignment4Horizontal(this, value); - switch (horizontal_alignment) { - case Constants.CENTER: - sb.append(" tac"); - break; - case Constants.RIGHT: - sb.append(" tar"); - break; - } - switch (this.vertical_alignment) { - case Constants.BOTTOM: - sb.append(" vab"); - break; - case Constants.TOP: - sb.append(" vat"); - break; - } - - if (this.textStyle != NewFormStyle.TEXTSTYLE_WRAPTEXT - && this.textStyle != NewFormStyle.TEXTSTYLE_MULTILINEADJUSTFONT) { - sb.append(" nw"); - } else { - sb.append(" bw"); // alex:只可以用于ie,英文的长单词会被换行分开 - } - - FRFont font = this.getFRFont(); - if (font != null) { - sb.append(font2Class(font, contentCssMap, lineSpacing)); - } - - int lit = this.paddingLeft; - int rit = this.paddingRight; - int tit = this.spacingBefore; - int bit = this.spacingAfter; - //这边的<= 包括下面<>修改的话, 都要做好兼容的 - if (lit <= DEFAULT_PADDING) { - sb.append(" pl" + lit); - } else { - contentCssMap.put("padding-left", lit + "pt"); - } - - if (rit < DEFAULT_PADDING) { - sb.append(" pr" + rit); - } else if (rit > DEFAULT_PADDING) { - contentCssMap.put("padding-right", rit + "pt"); - } - - if (0 < tit && tit <= DEFAULT_PADDING) { - sb.append(" pt" + tit); - } else if (tit > DEFAULT_PADDING) { - contentCssMap.put("padding-top", tit + "pt"); - } - - if (0 < bit && bit <= DEFAULT_PADDING) { - sb.append(" pb" + bit); - } else if (bit > DEFAULT_PADDING) { - contentCssMap.put("padding-bottom", bit + "pt"); - } - - return sb.toString().trim(); - } - - public JSONObject border2JSONObject() throws JSONException { - JSONObject borderJSON = new JSONObject(); - if (checkLeftRightTopBottom4b1()) { - borderJSON.put("b1", true); - } else { - border2JSONObject(borderJSON, border_top, border_top_color, "t"); - border2JSONObject(borderJSON, border_left, border_left_color, "l"); - border2JSONObject(borderJSON, border_bottom, border_bottom_color, "b"); - border2JSONObject(borderJSON, border_right, border_right_color, "r"); - } - return borderJSON; - } - - private void border2JSONObject(JSONObject jo, byte borderStyle, Color borderColor, String position) throws JSONException { - if (borderStyle == Constants.LINE_THIN - && ComparatorUtils.equals(borderColor, Color.black)) { - jo.put(position, new JSONObject().put("w", 1)); - } else { - int bw = BaseUtils.getBorderWidth(borderStyle); - if (bw > 0) { - JSONObject extra = new JSONObject(); - extra.put("w", bw); - if (!ComparatorUtils.equals(borderColor, Color.black)) { - extra.put("c", StableUtils.javaColorToCSSColor(borderColor)); - } - // 留着保持兼容老的app - extra.put("s", borderLine2String(borderStyle)); - // MOBILE-21527 报表设计器设置不同的border后台返回具体的border类型 - extra.put("type", borderStyle); - jo.put(position, extra); - } - } - } - - private String borderLine2String(int borderStyle) { - switch (borderStyle) { - case Constants.LINE_THIN: - case Constants.LINE_SLIM: - return "t"; - case Constants.LINE_MEDIUM: - return "m"; - case Constants.LINE_THICK: - return "tk"; - case Constants.LINE_DOUBLE: - return "de"; - case Constants.LINE_DOT: - return "dt"; - case Constants.LINE_DASH_DOT: - return "dadt"; - case Constants.LINE_DASH_DOT_DOT: - return "ddd"; - default: - return "dash"; - } - } - - /* - * 返回classBuf与styleBuf - */ - private String border2Class(Map borderCssMap) { - StringBuilder sb = new StringBuilder(); - // 简化class - if (checkLeftRightTopBottom4b0()) { - sb.append(" b0"); - return sb.toString().trim(); - } else if (checkLeftRightTopBottom4b1()) { - sb.append(" b1"); - return sb.toString().trim(); - } - - // right - visible_border_css(this.border_right, this.border_right_color, sb, borderCssMap, "r"); - // bottom - visible_border_css(this.border_bottom, this.border_bottom_color, sb, borderCssMap, "b"); - // left - visible_border_css(this.border_left, this.border_left_color, sb, borderCssMap, "l"); - // top - visible_border_css(this.border_top, this.border_top_color, sb, borderCssMap, "t"); - - return sb.toString().trim(); - } - - private boolean checkLeftRightTopBottom4b0() { - return this.border_left == Constants.LINE_NONE && this.border_right == Constants.LINE_NONE - && this.border_top == Constants.LINE_NONE && this.border_bottom == Constants.LINE_NONE; - } - - private boolean checkLeftRightTopBottom4b1() { - return this.border_left == Constants.LINE_THIN && this.border_right == Constants.LINE_THIN - && this.border_top == Constants.LINE_THIN && this.border_bottom == Constants.LINE_THIN - && ComparatorUtils.equals(this.border_left_color, Color.black) - && ComparatorUtils.equals(this.border_right_color, Color.black) - && ComparatorUtils.equals(this.border_top_color, Color.black) - && ComparatorUtils.equals(this.border_bottom_color, Color.black); - } - - private static void visible_border_css( - byte border_style, Color border_color, StringBuilder classBuf, Map borderCssMap, String border_position - ) {// right - if (border_style == Constants.LINE_THIN - && ComparatorUtils.equals(border_color, Color.black)) { - classBuf.append(" b" + border_position + "1"); - } - - int bw = BaseUtils.getBorderWidth(border_style); - if (bw > 0) { - // width - classBuf.append(" b" + border_position + "w" + bw); - - // style - classBuf.append(" " + __border2Class(border_style, border_position)); - - // color - // 细线需要另外处理为 rgba,rgba的边框在chrome上会出现渲染问题 - // 转为 rgb 显示 - if (border_style == Constants.LINE_SLIM) { - borderCssMap.put(_position2Colorcss(border_position), - StableUtils.javaColorToCSSColor(brighter(border_color))); - } else if (ComparatorUtils.equals(border_color, Color.black)) { - classBuf.append(" b" + border_position + "cb"); - } else { - borderCssMap.put(_position2Colorcss(border_position), StableUtils.javaColorToCSSColor(border_color)); - } - } else { - classBuf.append(" b" + border_position + "0"); - } - } - - private static Color brighter(Color ori) { - return new Color(Math.min((int) ((1 - FACTORY_ALPHA) * 255 + FACTORY_ALPHA * ori.getRed()), 255), - Math.min((int) ((1 - FACTORY_ALPHA) * 255 + FACTORY_ALPHA * ori.getGreen()), 255), - Math.min((int) ((1 - FACTORY_ALPHA) * 255 + FACTORY_ALPHA * ori.getBlue()), 255), - 255); - } - - private static String _position2Colorcss(String border_position) { - if (ComparatorUtils.equals(border_position, "r")) { - return "border-right-color"; - } else if (ComparatorUtils.equals(border_position, "b")) { - return "border-bottom-color"; - } else if (ComparatorUtils.equals(border_position, "l")) { - return "border-left-color"; - } else if (ComparatorUtils.equals(border_position, "t")) { - return "border-top-color"; - } else { - return "border-color"; - } - } - - private static String __border2Class(int borderStyle, String d) { - switch (borderStyle) { - case Constants.LINE_SLIM: - return "b" + d + "ss"; - case Constants.LINE_THIN: - return "b" + d + "ss"; - case Constants.LINE_MEDIUM: - return "b" + d + "ss"; - case Constants.LINE_THICK: - return "b" + d + "ss"; - case Constants.LINE_DOUBLE: - return "b" + d + "sd"; - case Constants.LINE_DOT: - return "b" + d + "sdo"; - case Constants.LINE_DASH_DOT: - return "b" + d + "sdo"; - case Constants.LINE_DASH_DOT_DOT: - return "b" + d + "sdo"; - default: - return "b" + d + "sda"; - } - } - - private static String font2Class(Font font, Map cssMap, byte lineSpacing) { - StringBuilder sb = new StringBuilder(); - if (font.isBold()) { - sb.append(" fwb"); - } - if (font.isItalic()) { - sb.append(" fsi"); - } - String fontName = font.getName(); - String cls = (String) getclsFontFamily().get(fontName); - if (cls == null) { - // REPORT-25741 部分字体需要加引号才能识别 - cssMap.put("font-family", "'" + fontName + "'"); - } else if (!ComparatorUtils.equals(cls, "fnss")) { // alex:font-family:SimSun写在fh里面了 - sb.append(" " + cls); - } - float size = font.getSize2D(); - if (AssistUtils.equals(size, N_SIZE)) { // alex:font-size:9pt写在fh里面 - } else if (size >= MIN_SIZE && size <= MAX_SIZE) { - size = Utils.round5(size); - sb.append(" f" + String.valueOf(size).replace('.', '-')); - } else { - cssMap.put("font-size", font.getSize2D() + "pt"); - } - - if (lineSpacing != 0) { - // carl:直接在这里添上line-height - //cellFM.getHeight() 不能简单的 *(4/3)进行转换,数值不对 - FontMetrics cellFM = GraphHelper.getFontMetrics(FRFont.getInstance(font).applyResolutionNP(Constants.FR_PAINT_RESOLUTION)); - cssMap.put("line-height", (int) (cellFM.getHeight() + lineSpacing * LINE_HEIGHT_FIX / LINE_HEIGHT_FIX2) + "px"); - } - - font2ClassOnFRFont(font, cssMap, sb); - - return sb.toString(); - } - - private static void font2ClassOnFRFont(Font font, Map cssMap, StringBuilder sb) { - if (font instanceof FRFont) { - if (((FRFont) font).isStrikethrough()) { - if (((FRFont) font).getUnderline() != Constants.LINE_NONE) { - sb.append(" tdstu"); - } else { - sb.append(" tdst"); - } - } else { - if (((FRFont) font).getUnderline() != Constants.LINE_NONE) { - sb.append(" tdu"); - } - } - if (((FRFont) font).isSubscript()) { - sb.append(" suber"); - } else if (((FRFont) font).isSuperscript()) { - sb.append(" super"); - } - if (((FRFont) font).isShadow()) { - sb.append(" shadow"); - } - Color color = ((FRFont) font).getForeground(); - if (!ComparatorUtils.equals(color, Color.black) && color != null) { - cssMap.put("color", StableUtils.javaColorToCSSColor(color)); - } - } - } - - - private transient int hashCode = -1; - - /** - * 哈希码 - * - * @return 哈希值h - */ - public int hashCode() { - - if (hashCode == -1) { - //因为format和非ColorBackground的Background并不是唯一的(也就是说即使equals但hashCode也会不一样),所以不放在hashCode的计算里面 - int code = this.border_top ^ this.border_bottom ^ this.border_left ^ this.border_right ^ - this.border_top_color.hashCode() ^ this.border_bottom_color.hashCode() ^ - this.border_left_color.hashCode() ^ this.border_right_color.hashCode() ^ - this.horizontal_alignment ^ this.imageLayout ^ this.verticalText ^ - this.paddingLeft ^ this.paddingRight ^ this.rotation ^ this.textDirection ^ this.textStyle ^ this.vertical_alignment; - - if (frFont != null) { - code ^= frFont.hashCode(); - } - if (background != null) { - code = background.fixHashCode(code); - } - hashCode = code; - } - return hashCode; - } - - /** - * Equals. - */ - public boolean equals(Object object) { - if (object == this) { - return true; - } - if (!(object instanceof NewFormStyle)) { - return false; - } - - NewFormStyle newStyle = (NewFormStyle) object; - - //由于java中所有的Format都实现了equals()方法,这里可以直接来比较. - return ComparatorUtils.equals(newStyle.getFormat(), this.getFormat()) && - ComparatorUtils.equals(newStyle.getFRFont(), this.getFRFont()) && - ComparatorUtils.equals(newStyle.getBackground(), this.getBackground()) && - - newStyle.getBorderTop() == this.getBorderTop() && - newStyle.getBorderLeft() == this.getBorderLeft() && - newStyle.getBorderBottom() == this.getBorderBottom() && - newStyle.getBorderRight() == this.getBorderRight() && - - ComparatorUtils.equals(newStyle.getBorderTopColor(), this.getBorderTopColor()) && - ComparatorUtils.equals(newStyle.getBorderLeftColor(), this.getBorderLeftColor()) && - ComparatorUtils.equals(newStyle.getBorderBottomColor(), this.getBorderBottomColor()) && - ComparatorUtils.equals(newStyle.getBorderRightColor(), this.getBorderRightColor()) && - - BaseUtils.getAlignment4Horizontal(newStyle) == BaseUtils.getAlignment4Horizontal(this) && - newStyle.getVerticalAlignment() == this.getVerticalAlignment() && - newStyle.getTextStyle() == this.getTextStyle() && - - //james verticalText - newStyle.getVerticalText() == this.getVerticalText() && - newStyle.getTextDirection() == this.getTextDirection() && - newStyle.getRotation() == this.getRotation() && - newStyle.getImageLayout() == this.getImageLayout() && - - // alex padding - newStyle.getPaddingLeft() == this.getPaddingLeft() && - newStyle.getPaddingRight() == this.getPaddingRight() && - - //间距 - newStyle.getSpacingBefore() == this.getSpacingBefore() && - newStyle.getSpacingAfter() == this.getSpacingAfter() && - newStyle.getLineSpacing() == this.getLineSpacing(); - } - - /** - * Clone. - */ - public Object clone() throws CloneNotSupportedException { - return this; - } - - protected Object readResolve() throws InvalidObjectException { - if (this.getClass() != NewFormStyle.class) { - throw new InvalidObjectException("subclass didn't correctly implement readResolve"); - } - - Object res = initializeStyle.get(this); - //alex:从ObjectInputStream生成的Object可能不存在于全局的map中,可能为null - if (res == null) { - res = this; - initializeStyle.put(this, res); - } - - return res; - } - - /** - * 画单元格的Value - *

- * 通过width, height方式画 - */ - public static void paintContent(Graphics2D g2d, Object value, NewFormStyle style, int width, int height, int resolution) { - // kunsnat: 添加判断width和height. 是否有必要继续paint, @bug0006854, 增加了混乱的字符. - if (value == null || width == 0 || height == 0) { - return; - } - - if (style == null) { - //peter:获取默认的Style. - style = NewFormStyle.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER); - } - - if (value instanceof BaseFormula) { - value = ((BaseFormula) value).getResult(); - } - - if (value instanceof Painter) { - // TODO 弹出界面然后 esc bug.. - ((Painter) value).paint(g2d, width, height, resolution, style); - } else if (value instanceof ImageProvider) { - paintImageContent(g2d, ((ImageProvider) value).getImage(), style, width, height, resolution); - } else if (value instanceof Image) { - paintImageContent(g2d, (Image) value, style, width, height, resolution); - } else { - //默认Paint String - String text = valueToText(value, style.getFormat()); - paintCellStyleString(g2d, width, height, text, style, resolution); - } - } - - public static void paintImageContent(Graphics2D g2d, Image value, NewFormStyle style, int width, int height, int resolution) { - int imageLayout = CoreGraphHelper.changeImageLayout4Draw(value, style.getImageLayout(), width, height); - - //这边做scale的目的是为了在导出图片以及以图片方式打印时,根据不同的resolution调整对应的dpi - int defaultResolution = Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION; - double scale = resolution * 1d / defaultResolution; - width = (int) (width / scale); - height = (int) (height / scale); - g2d.scale(scale, scale); - - GraphHelper.paintImage(g2d, width, height, value, imageLayout, - style.getHorizontalAlignment(), style.getVerticalAlignment(), -1, -1); - //最后把画板改回来 - g2d.scale(defaultResolution * 1d / resolution, defaultResolution * 1d / resolution); - } - - /** - * 画单元格的Value - *

- * 通过PaintRectangle + ClipRectangle画 - */ - public static void paintContent(Graphics2D g2d, Object value, int resolution, NewFormStyle style, Rectangle paintRectangle, Rectangle clipRectangle) { - Shape oldClip = g2d.getClip(); - g2d.translate(paintRectangle.getX(), paintRectangle.getY()); - g2d.clip(clipRectangle); // kunsnat: 这些clip 都没有考虑边框啊!!! 所有图表的边框压缩到里面去了. - - paintContent(g2d, value, style, paintRectangle.width, paintRectangle.height, resolution); - - g2d.translate(-paintRectangle.getX(), -paintRectangle.getY()); - g2d.setClip(oldClip); - } - - /** - * 画背景 - *

- * 通过width, height方式画 - */ - public static void paintBackground(Graphics2D g2d, NewFormStyle style, double width, double height) { - if (style == null) {// 还是需要检查一下的,假如DefaultCellStyle拥有Border就需要Paint了. - return; - } - - // paint background. - Background background = style.getBackground(); - if (background == null) { - return; - } - - background.layoutDidChange((int) width, (int) height); - synchronized (tempRectangle2D) { - tempRectangle2D.setRect(0, 0, width, height); - background.paint(g2d, tempRectangle2D); - } - } - - /** - * 画单元格的背景 - *

- * 通过PaintRectangle + ClipRectangle画 - */ - public static void paintBackground(Graphics2D g2d, NewFormStyle style, Rectangle paintRectangle, Rectangle clipRectangle) { - if (style == null) { - //peter:获取默认的Style. - style = NewFormStyle.DEFAULT_STYLE; - } - Shape oldClip = g2d.getClip(); - g2d.translate(paintRectangle.getX(), paintRectangle.getY()); - g2d.clip(clipRectangle); - Background background = style.getBackground(); - - if (background != null) { - // alex:根据paintRectangle和clipRectangle共同决定Background的PaintRectangle - background.paint(g2d, new Rectangle( - clipRectangle.x, clipRectangle.y, - clipRectangle.width, clipRectangle.height)); - } - g2d.translate(-paintRectangle.getX(), -paintRectangle.getY()); - g2d.setClip(oldClip); - } - - /** - * 画边框 - *

- * 通过width, height方式画 - */ - public static void paintBorder(Graphics2D g2d, NewFormStyle style, double width, double height) { - if (style == null) {// 还是需要检查一下的,假如DefaultCellStyle拥有Border就需要Paint了. - return; - } - - //peter:当是粗线的时候,需要计算尺寸 - double left = 0; - double right = 0; - if (style.getBorderLeft() != Constants.LINE_NONE) { - int borderLeftSize = GraphHelper.getLineStyleSize(style.getBorderLeft()); - left = borderLeftSize / 2; - } - if (style.getBorderRight() != Constants.LINE_NONE) { - int borderRightSize = GraphHelper.getLineStyleSize(style.getBorderRight()); - right = borderRightSize / 2; - } - - double top = 0; - double bottom = 0; - if (style.getBorderTop() != Constants.LINE_NONE) { - int bSize = GraphHelper.getLineStyleSize(style.getBorderTop()); - top = bSize / 2; - } - if (style.getBorderBottom() != Constants.LINE_NONE) { - int bSize = GraphHelper.getLineStyleSize(style.getBorderBottom()); - bottom = bSize / 2; - } - - // paint border - if (style.getBorderTop() != Constants.LINE_NONE) { - g2d.setPaint(style.getBorderTopColor()); - GraphHelper.drawLine(g2d, 0 - left, 0, width + right, 0, style.getBorderTop()); - } - if (style.getBorderLeft() != Constants.LINE_NONE) { - g2d.setPaint(style.getBorderLeftColor()); - GraphHelper.drawLine(g2d, 0, 0 - top, 0, height + bottom, style.getBorderLeft()); - } - if (style.getBorderBottom() != Constants.LINE_NONE) { - g2d.setPaint(style.getBorderBottomColor()); - GraphHelper.drawLine(g2d, 0 - left, height, width + right, height, style.getBorderBottom()); - } - if (style.getBorderRight() != Constants.LINE_NONE) { - g2d.setPaint(style.getBorderRightColor()); - GraphHelper.drawLine(g2d, width, 0 - top, width, height + bottom, style.getBorderRight()); - } - } - - /** - * 画单元格的边框 - *

- * 通过PaintRectangle + ClipRectangle画边框 - */ - public static void paintBorder(Graphics2D g2d, NewFormStyle style, Rectangle paintRectangle, Rectangle clipRectangle) { - //单元格行高列宽=0时, 不需要绘制边框 - if (paintRectangle.width == 0 || paintRectangle.height == 0) { - return; - } - g2d.translate(paintRectangle.getX(), paintRectangle.getY()); - - Rectangle realPaintRect = new Rectangle(0, 0, - paintRectangle.width, paintRectangle.height); - //peter:需要判断的因为clipRectangle极可能不是null. - if (clipRectangle != null) { - realPaintRect = realPaintRect.intersection(clipRectangle); - } - g2d.translate(realPaintRect.getX(), realPaintRect.getY()); - - if (style == null) {// 还是需要检查一下的,假如DefaultCellStyle拥有Border就需要Paint了. - //peter:获取默认的Style. - style = NewFormStyle.DEFAULT_STYLE; - } - - paintBorder(g2d, style, realPaintRect.getWidth(), realPaintRect.getHeight()); - - // 返回Translate - g2d.translate(-realPaintRect.getX(), -realPaintRect.getY()); - g2d.translate(-paintRectangle.getX(), -paintRectangle.getY()); - } - - /** - * 转化成文本 - * - * @param value 带转化的对象 - * @param format 格式g - * @return 字符串z - */ - public static String valueToText(Object value, Format format) { - //需要画的值,主要是把公式里面的值拿出来 - Object valueToPaint = value; - String text = null; - - String checkInfinity = StableUtils.checkInfinity(value); - if (StringUtils.isNotEmpty(checkInfinity)) { - return checkInfinity; - } - - if (value != null) { - if (value instanceof BaseFormula) { - BaseFormula formula = (BaseFormula) value; - if (StableUtils.isNull(formula.getResult())) { - return StringUtils.EMPTY;// BUG4788,应该显示空字符串 - } else { - valueToPaint = formula.getResult(); - } - } else if (value instanceof Clob) { - valueToPaint = DataBaseUtils.clob2String((Clob) value); - } - - if (format != null) { - format = FormatRepository.getInstance().getLocalFormat(format); - if (format instanceof DateFormat) {// Date. - text = valueInDateFormat((DateFormat) format, valueToPaint); - } else if (format instanceof NumberFormat) {// Number. - text = valueInNumberFormat(format, valueToPaint); - } else { - try { - text = format.format(valueToPaint); - } catch (Exception exp) { - text = Utils.objectToString(valueToPaint); - } - } - } else - text = Utils.objectToString(valueToPaint); - } else { - text = StringUtils.EMPTY; - } - - return text; - } - - protected static String valueInNumberFormat(Format format, Object valueToPaint) { - Number number = GeneralUtils.objectToNumberReturnNull(valueToPaint); - if (number != null) { - try { - if (format instanceof CoreDecimalFormat) { - //数字类型的要roundup一下, 默认会逢5奇进偶不进, 62.325->62.33 - return ((CoreDecimalFormat) format).formatRoundingModeUp(number); - } - //62.325->62.32 - return format.format(number); - } catch (Exception ignore) { - } - } - return Utils.objectToString(valueToPaint); - } - - private static String valueInDateFormat(DateFormat format, Object valueToPaint) { - - String result; - Date date2Format = tryGet(format, valueToPaint); - if (date2Format == null) { - date2Format = DateUtils.object2Date(valueToPaint, true); - } - if (date2Format != null) { - result = format.format(date2Format); - } - /* - * alex:如果date2Format为null,就是说valueToPaint不能转换成日期型,那么就直接画valueToPaint的字符串 - * 为什么必须要画valueToPaint的字符串呢?见bug0004566 - * 因为在Grid里面直接写=today(),并设置format为日期,如果不画,就一片空白,什么都看不到了 - */ - else { - result = Utils.objectToString(valueToPaint); - } - - return result; - } - - @Nullable - private static Date tryGet(DateFormat format, Object valueToPaint) { - - Date date2Format = null; - // 先用format来生成日期啊 - if (valueToPaint instanceof Date) { - date2Format = (Date) valueToPaint; - } else { - try { - date2Format = format.parse(GeneralUtils.objectToString(valueToPaint)); - } catch (Exception e) { - // nothing - } - } - return date2Format; - } - - /** - * Paint string according to Style. - */ - public static void paintCellStyleString2(Graphics2D g2d, int width, int height, String text, Style style, int resolution) { - if (StringUtils.isBlank(text)) { - return; - } - Paint oldPaint = g2d.getPaint(); - if (style == null) { - style = NewFormStyle.DEFAULT_STYLE; - } - Font rfont = BaseUtils.getStyleFont(g2d, style, resolution); - if (style.getRotation() != 0 && style.getVerticalText() == NewFormStyle.HORIZONTALTEXT) { - BaseUtils.drawStringStyleInRotation(g2d, width, height, text, style, resolution); - } else { - if (style.getTextStyle() == NewFormStyle.TEXTSTYLE_SINGLELINEADJUSTFONT - || style.getTextStyle() == NewFormStyle.TEXTSTYLE_MULTILINEADJUSTFONT) { - List lineTextList = BaseUtils.getLineTextList(text, style, rfont, height, width, resolution); - if (width <= 0 || lineTextList.isEmpty()) { - return; - } - int textAscent = g2d.getFontMetrics().getAscent(); - int textHeight = g2d.getFontMetrics().getHeight(); - - int textY = 0; - int textAllHeight = textHeight * lineTextList.size(); - double spacingBefore = PT.pt2pix(style.getSpacingBefore(), resolution); - double spacingAfter = PT.pt2pix(style.getSpacingAfter(), resolution); - double lineSpacing = PT.pt2pix(style.getLineSpacing(), resolution); - //james:加上间距,WORD中的行间距是从第一行文本的上面一行就算的,所以行间距形成的空隙与文本行数相同 - textAllHeight += spacingBefore + spacingAfter + lineSpacing * lineTextList.size(); - if (style.getVerticalAlignment() == Constants.CENTER) { - if (height > textAllHeight) {// 如果所有文本的高度小于当前可以绘区域的高度,就从0开始画字符. - textY = (height - textAllHeight) / 2; - } - } else if (style.getVerticalAlignment() == Constants.BOTTOM) { - textY = height - textAllHeight; - } - textY += textAscent;// 在绘画的时候,必须添加Ascent的高度. - textY += spacingBefore + lineSpacing;//james:加上"段前间距"+“行间距” - if (style.getTextStyle() == NewFormStyle.TEXTSTYLE_SINGLELINEADJUSTFONT) {// 通过自动调整字体显示所有的信息调整Font来显示所有的字符 - ContentLineGroup contentLineGroup = singleLineAdjustFont(style, lineTextList, width, height, g2d, resolution, true); - _drawContentLineGroup(contentLineGroup, g2d, textY, height, width, BaseUtils.getAlignment4Horizontal(style, text)); - } else if (style.getTextStyle() == NewFormStyle.TEXTSTYLE_MULTILINEADJUSTFONT) { - ContentLineGroup contentLineGroup = mulitiLineAdjustFont(style, lineTextList, width, height, g2d, resolution, true); - _drawContentLineGroup(contentLineGroup, g2d, textY, height, width, BaseUtils.getAlignment4Horizontal(style, text)); - } - } else { - BaseUtils.drawStringStyleInRotation(g2d, width, height, text, style, resolution); - } - } - g2d.setPaint(oldPaint); - } - - - - private static void _drawContentLineGroup( - ContentLineGroup contentLineGroup, Graphics2D g2d, - int textY, int height, int width, int horizontalAlignment - ) { - Style style = contentLineGroup.style; - - Font oldFRFont = g2d.getFont(); - g2d.setFont(style.getFRFont()); - if (style.getVerticalAlignment() == Constants.TOP) { - textY = 0; - } else if (style.getVerticalAlignment() == Constants.CENTER) { - if (height > contentLineGroup.totalHeight()) {// 如果所有文本的高度小于当前可以绘区域的高度,就从0开始画字符. - textY = (height - contentLineGroup.totalHeight()) / 2; - } else { - textY = 0; - } - } else if (style.getVerticalAlignment() == Constants.BOTTOM) { - textY = height - contentLineGroup.totalHeight(); - } - textY += g2d.getFontMetrics().getAscent();// 在绘画的时候,必须添加Ascent的高度. - - for (int i = 0; i < contentLineGroup.newLineTextList.size(); i++) { - double textX = style.getPaddingLeft(); - int textWidth = GraphHelper.getFontMetrics(style.getFRFont()).stringWidth((String) contentLineGroup.newLineTextList.get(i)); - if (horizontalAlignment == Constants.CENTER) { - textX = (width - textWidth - style.getPaddingRight()) / 2.0; - } else if (horizontalAlignment == Constants.RIGHT) { - textX = width - style.getPaddingRight() - textWidth; - } else if (horizontalAlignment == Constants.DISTRIBUTED) {// added by KevinWang - } - - if (horizontalAlignment == Constants.DISTRIBUTED) { - String lineText = (String) contentLineGroup.newLineTextList.get(i);// 分行显示时第i行的内容,但是也可能单行 - double charSpace = (width - style.getPaddingLeft() - style.getPaddingRight() - - g2d.getFontMetrics().charWidth(lineText.charAt(lineText.length() - 1))) - / (lineText.length() - 1); - for (int charIndex = 0; charIndex < lineText.length(); charIndex++) { - char tmpChar = lineText.charAt(charIndex);//取出一个字符待显示 - String tmpString = new String((new StringBuffer()).append(tmpChar));// 将其包装成string形式 - double charX = style.getPaddingLeft() + charIndex * charSpace; - GraphHelper.drawString(g2d, tmpString, charX, textY);//显示 - } - } else { - GraphHelper.drawString(g2d, (String) contentLineGroup.newLineTextList.get(i), textX, textY); - } - textY += contentLineGroup.newTextHeight; - } - g2d.setFont(oldFRFont); - } - - /* - * 通过自动调整字体显示所有的信息调整Font来显示所有的字符 - */ - private static ContentLineGroup singleLineAdjustFont(Style style, List lineTextList, int width, int height, Graphics2D g2d, int resolution, boolean fontScale) { - FRFont newFRFont = (FRFont) style.getFRFont().applyResolutionNP(resolution); - - int maxTextWidth = 0; - FontMetrics oriFontMetrics = GraphHelper.getFontMetrics(newFRFont); - int maxTextHeight = oriFontMetrics.getHeight() * lineTextList.size(); - String examle_text = ""; - for (int i = 0; i < lineTextList.size(); i++) { - if (oriFontMetrics.stringWidth((String) lineTextList.get(i)) > maxTextWidth) { - examle_text = (String) lineTextList.get(i); - maxTextWidth = oriFontMetrics.stringWidth((String) lineTextList.get(i)); - } - } - - if (maxTextWidth > 0 || maxTextHeight > 0) { // 只有当大于0时才改变字体大小 - // 调整宽度和高度 - if (maxTextWidth > (width - style.getPaddingLeft() - style.getPaddingRight()) || maxTextHeight > height) { - while (newFRFont.getSize() > 1) { - newFRFont = newFRFont.applySize((float) newFRFont.getSize() - 1); - maxTextWidth = GraphHelper.getFontMetrics(newFRFont).stringWidth(examle_text); - maxTextHeight = GraphHelper.getFontMetrics(newFRFont).getHeight() * lineTextList.size(); - - // 由于Font的变化单位是1, 所以必须这么找最适合的 Font - if (maxTextWidth <= (width - style.getPaddingLeft() - style.getPaddingRight()) && maxTextHeight <= height) { - break; - } - } - } - } - - FRFont returnFont = style.getFRFont().applySize(fontScale ? newFRFont.getSize2D() : FRFont.convResolution(newFRFont.getSize2D(), resolution)); - return new ContentLineGroup(style.deriveFRFont(returnFont), lineTextList, GraphHelper.getFontMetrics(newFRFont, g2d).getHeight()); - } - - /* - * 多行显示(调整字体大小),即固定单元格高和框,改变字体大小使适应。 - */ - private static ContentLineGroup mulitiLineAdjustFont(Style style, List lineTextList, int width, int height, Graphics2D g2d, int resolution, boolean fontScale) { - FRFont newFRFont = (FRFont) style.getFRFont().applyResolutionNP(resolution); - List newLineTextList; - NewFormStyle tmpStyle = NewFormStyle.DEFAULT_STYLE; - tmpStyle = tmpStyle.deriveTextStyle(NewFormStyle.TEXTSTYLE_WRAPTEXT); - int newTextHeight = GraphHelper.getFontMetrics(newFRFont, g2d).getHeight(); - - newLineTextList = resovleLineTextListByStyle(newFRFont, lineTextList, tmpStyle, width, resolution); - - if (newLineTextList.size() * newTextHeight > height) { - while (newFRFont.getSize() > 1) { - newFRFont = newFRFont.applySize((float) newFRFont.getSize() - 1); - newLineTextList = resovleLineTextListByStyle(newFRFont, lineTextList, tmpStyle, width, resolution); - - newTextHeight = GraphHelper.getFontMetrics(newFRFont, g2d).getHeight(); - if (newLineTextList.size() * newTextHeight <= height) { - break; - } - } - } else if (newLineTextList.size() * newTextHeight < height) { - while (newFRFont.getSize() < MAX_FONT_SIZE) { // _denny: 设定字体最大为100 - newFRFont = newFRFont.applySize((float) newFRFont.getSize() + 1); - - newLineTextList = resovleLineTextListByStyle(newFRFont, lineTextList, tmpStyle, width, resolution); - - newTextHeight = GraphHelper.getFontMetrics(newFRFont, g2d).getHeight(); - if (newLineTextList.size() * newTextHeight > height) { - newFRFont = newFRFont.applySize(newFRFont.getSize() - 1); - - newLineTextList = resovleLineTextListByStyle(newFRFont, lineTextList, tmpStyle, width, resolution); - - newTextHeight = GraphHelper.getFontMetrics(newFRFont, g2d).getHeight(); - break; - } - } - } - - FRFont returnFont = tmpStyle.getFRFont().applySize(fontScale ? newFRFont.getSize2D() : FRFont.convResolution(newFRFont.getSize2D(), resolution)); - tmpStyle.deriveFRFont(returnFont); - - return new ContentLineGroup(tmpStyle, newLineTextList, newTextHeight); - } - - private static List resovleLineTextListByStyle(Font font, List lineTextList, NewFormStyle tmpStyle, int width, int resolution) { - List newLineTextList = new ArrayList(); - - List tmpLineTextList; - for (int i = 0; i < lineTextList.size(); i++) { - tmpLineTextList = BaseUtils.getLineTextList((String) lineTextList.get(i), tmpStyle, font, width, resolution); - for (int j = 0; j < tmpLineTextList.size(); j++) { - newLineTextList.add((String) tmpLineTextList.get(j)); - } - } - - return newLineTextList; - } - - /** - * 修改格子样式 - * - * @param width 宽 k - * @param height 高g - * @param text 文本w - * @param style 样式y - * @param resolution 转化率z - * @return 样式 y - */ - public static Style modCellStyleString(int width, int height, String text, Style style, int resolution) { - List lineTextList = BaseUtils.getLineTextList(text, style, null, height, width, resolution); - if (style.getTextStyle() == NewFormStyle.TEXTSTYLE_SINGLELINEADJUSTFONT) { - style = singleLineAdjustFont(style, lineTextList, width, height, null, resolution, false).style; - } else if (style.getTextStyle() == NewFormStyle.TEXTSTYLE_MULTILINEADJUSTFONT) { - style = mulitiLineAdjustFont(style, lineTextList, width, height, null, resolution, false).style; - } - - return style; - } -} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeAutoChangeLine.java b/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeAutoChangeLine.java new file mode 100644 index 000000000..0037c738d --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeAutoChangeLine.java @@ -0,0 +1,20 @@ +package com.fr.design.fit.common; + +import com.fr.base.DefaultAutoChangeLine; +import com.fr.base.Style; +import com.fr.stable.unit.UNIT; + +import java.awt.Font; +import java.util.List; + +public class NewUIModeAutoChangeLine extends DefaultAutoChangeLine { + @Override + public List textAutoChangeLine(String text, Font font, Style style, UNIT unitWidth, int resolution) { + return autoChangeLine(text, font, style, unitWidth, resolution); + } + + protected double calculateShowWidth(double paintWidth, Style style, int resolution) { + return paintWidth - style.getPaddingLeft() - style.getPaddingRight() - style.getBorderLeftWidth(); + } + +} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeRotationDraw.java b/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeRotationDraw.java new file mode 100644 index 000000000..3e0b06721 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/fit/common/NewUIModeRotationDraw.java @@ -0,0 +1,69 @@ +package com.fr.design.fit.common; + +import com.fr.base.BaseUtils; +import com.fr.base.DefaultRotationTextDrawProvider; +import com.fr.base.GraphHelper; +import com.fr.base.Style; +import com.fr.design.mainframe.PX; +import com.fr.stable.Constants; + +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.util.List; + +public class NewUIModeRotationDraw extends DefaultRotationTextDrawProvider { + @Override + public void drawRotationText(Graphics2D g2d, String text, Style style, Font rfont, int width, int height, int horizontalAlignment, int resolution) { + FontMetrics cellFM = GraphHelper.getFontMetrics(rfont); + List lineTextList = BaseUtils.getLineTextList(text, style, rfont, height, width, resolution, new NewUIModeAutoChangeLine()); + drawRotationText(g2d, lineTextList, style, cellFM, width, height, horizontalAlignment, resolution); + } + + + protected int calculateTextWidth(int width, Style style) { + return width - style.getPaddingRight(); + } + + protected double calculateTextX(Style style, int width, int textWidth, int horizontalAlignment, int resolution) { + double textX = padding2PixExcludeRight(style.getPaddingLeft(), resolution); + if (horizontalAlignment == Constants.CENTER) { + textX += (width - textWidth - textX) / 2f; + } else if (horizontalAlignment == Constants.RIGHT) { + textX = width - style.getPaddingRight() - textWidth; + } + return textX; + } + + protected int toPXWithResolution(double pt, int resolution) { + return (int) PX.toPixWithResolution(pt, resolution); + } + + protected double padding2PixExcludeRight(int padding, int resolution) { + return PX.toPixWithResolution(padding, resolution); + } + + protected int calculateTextY(Style style, int height, int textHeight, int textAscent, List lineTextList, int resolution) { + // 计算Y的高度. + int textY = 0; + int textAllHeight = textHeight * lineTextList.size(); + double spacingBefore = toPXWithResolution(style.getSpacingBefore(), resolution); + double spacingAfter = toPXWithResolution(style.getSpacingAfter(), resolution); + double lineSpacing = toPXWithResolution(style.getLineSpacing(), resolution); + textAllHeight += spacingBefore + spacingAfter + lineSpacing * lineTextList.size(); + if (style.getVerticalAlignment() == Constants.TOP) { + } else if (style.getVerticalAlignment() == Constants.CENTER) { + if (height > textAllHeight) {// 如果所有文本的高度小于当前可以绘区域的高度,就从0开始画字符. + textY = (height - textAllHeight) / 2; + } + } else if (style.getVerticalAlignment() == Constants.BOTTOM) { + if (height > textAllHeight) { + textY = height - textAllHeight; + } + } + textY += textAscent;// 在绘画的时候,必须添加Ascent的高度. + textY += spacingBefore + lineSpacing;//james:加上"段前间距"+“行间距” + return textY; + } + +} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/PaintUtils.java b/designer-form/src/main/java/com/fr/design/fit/common/PaintUtils.java deleted file mode 100644 index 8f913a7aa..000000000 --- a/designer-form/src/main/java/com/fr/design/fit/common/PaintUtils.java +++ /dev/null @@ -1,835 +0,0 @@ -/* - * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. - */ -package com.fr.design.fit.common; - -import com.fr.base.AutoChangeLineAndDrawManager; -import com.fr.base.BaseFormula; -import com.fr.base.BaseUtils; -import com.fr.base.GraphHelper; -import com.fr.base.ImageProvider; -import com.fr.base.Painter; -import com.fr.base.Style; -import com.fr.base.Utils; -import com.fr.base.background.ColorBackground; -import com.fr.base.chart.BaseChartCollection; -import com.fr.base.chart.result.WebChartIDInfo; -import com.fr.code.BarcodeImpl; -import com.fr.code.bar.BarcodeException; -import com.fr.code.bar.core.BarCodeUtils; -import com.fr.code.bar.core.BarcodeAttr; -import com.fr.data.DataUtils; -import com.fr.data.PresentationType; -import com.fr.data.condition.ListCondition; -import com.fr.file.ResultChangeWhenExport; -import com.fr.form.ui.Widget; -import com.fr.general.Background; -import com.fr.general.ComparatorUtils; -import com.fr.general.FRFont; -import com.fr.general.ImageWithSuffix; -import com.fr.log.FineLoggerFactory; -import com.fr.plugin.ExtraClassManager; -import com.fr.report.cell.CellElement; -import com.fr.report.cell.FloatElement; -import com.fr.report.cell.TemplateCellElement; -import com.fr.report.cell.cellattr.CellExpandAttr; -import com.fr.report.cell.cellattr.CellGUIAttr; -import com.fr.report.cell.cellattr.core.CellUtils; -import com.fr.report.cell.cellattr.core.ResultSubReport; -import com.fr.report.cell.cellattr.core.group.DSColumn; -import com.fr.report.core.Html2ImageUtils; -import com.fr.report.core.ReportUtils; -import com.fr.script.Calculator; -import com.fr.stable.Constants; -import com.fr.stable.CoreConstants; -import com.fr.stable.StringUtils; -import com.fr.stable.bridge.ObjectHolder; -import com.fr.stable.fun.AutoChangeLineAndDrawProcess; -import com.fr.stable.fun.FontProcessor; -import com.fr.stable.html.Tag; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.PT; -import com.fr.stable.unit.UNIT; -import com.fr.stable.web.Repository; - -import javax.swing.ImageIcon; -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Paint; -import java.awt.Rectangle; -import java.awt.font.TextAttribute; -import java.awt.geom.GeneralPath; -import java.awt.image.BufferedImage; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; - -/** - * The util for paint. - */ -public class PaintUtils { - // Add by Denny - public static final int CELL_MARK_SIZE = 6; - public static final Color CELL_HIGHT_LIGHT_MARK_COLOR = new Color(255, 0, 55); - public static final Color CELL_PRESENT_MARK_COLOR = new Color(0, 255, 200); - public static final Color CELL_PAGINATION_MARK_COLOR = new Color(55, 255, 0); - public static final Color CELL_RESULT_MARK_COLOR = new Color(200, 0, 255); - public static final Color CELL_CONDITION_FILTER_MARK_COLOR = new Color(255, 200, 0); - public static final Color CELL_PARAMETER_FILTER_MARK_CONLR = new Color(0, 55, 255); - - public static final Color CELL_DIRECTION_MARK_COLOR = Color.gray; - private static final int UNIT_SIZE = 4; - - //原值是15,矩形线条会缺失,加1px绘制没问题。这地方有水印,但是貌似不是水印影响,未找到线条被挡住的原因 - private static final int WIDGET_WIDTH = 16; - private static final int WIDGET_HEIGHT = 16; - - // Suppresses default constructor, ensuring non-instantiability. - private PaintUtils() { - } - - // font attributes map cache - private static Hashtable fontAttributeMapCache = new Hashtable(); - - /* - * 用于在Grid里面画CellElement的Content + Background - * - * 不画Border,是因为在Grid里面先画所有单元格的Content + Background,再画所有单元格的Border(peter认为这可以提高速度) - */ - public static void paintGridCellContent(Graphics2D g2d, TemplateCellElement cell, int width, int height, int resolution) { - int cell_mark_size = CELL_MARK_SIZE; - // denny_Grid - // 左上角: 条件高亮, 形态 - int leftUpCount = 0; - int rightUpCount = 0; - int leftDownCount = 0; - GraphHelper.applyRenderingHints(g2d); - if (paintHighlightGroupMarkWhenExsit(g2d, cell, leftUpCount)) { - leftUpCount++; - } - if (paintPresentMarkWhenExsit(g2d, cell, leftUpCount)) { - leftUpCount++; - } - if (paintPaginationMarkWhenExsit(g2d, cell, width, rightUpCount)) { - rightUpCount++; - } - paintWidgetMarkWhenExsit(g2d, cell, width, height); - paintExpandMarkWhenExsit(g2d, cell); - Object value = cell.getValue(); - if (value == null) {// 先判断是否是空. - return; - } - if (paintResultMarkWhenExsit(g2d, value, width, rightUpCount)) { - rightUpCount++; - } - - if (paintDSColumnParametermarkWhenExsit(g2d, value, height, leftDownCount)) { - leftDownCount++; - } - - if (paintDSColumnConditionmarkWhenExsit(g2d, value, height, leftDownCount)) { - leftDownCount++; - } - // 画value,但因为是在Grid里面画,所以画Formula.content - if (value instanceof BaseFormula) { - value = ((BaseFormula) value).getContent(); - } - if (value instanceof ImageWithSuffix) { - value = ((ImageWithSuffix) value).getFineImage(); - } - if (value instanceof BaseChartCollection) { - value = ((BaseChartCollection) value).createResultChartPainterWithOutDealFormula(Calculator.createCalculator(), WebChartIDInfo.createEmptyDesignerInfo(), width, height); - } - // Carl:当是子报表时,在格子里画一个子报表的图 - /* - * alex:TODO 此处在Grid里面画ChartCollection和SubReport都只画一个图表,这种做法,很不雅 - */ - if (value instanceof ResultSubReport) { - value = BaseUtils.readImage("/com/fr/base/images/report/painter/subReport.png"); - GraphHelper.paintImage(g2d, width, height, (Image) value, Constants.IMAGE_CENTER, - BaseUtils.getAlignment4Horizontal(cell.getStyle(), value), cell.getStyle().getVerticalAlignment(), - width > 16 ? 16 : width, height > 16 ? 16 : height); - } else { - renderContent(g2d, value, cell.getStyle(), width, height, resolution); - } - } - - - private static void renderContent(Graphics2D g2d, Object value, Style style, int width, int height, int resolution) { - if (value != null && width != 0 && height != 0) { - if (style == null) { - style = Style.DEFAULT_STYLE.deriveImageLayout(1); - } - - if (value instanceof BaseFormula) { - value = ((BaseFormula) value).getResult(); - } - - if (value instanceof Painter) { - ((Painter)value).paint(g2d, width, height, resolution, style); - } else if (value instanceof ImageProvider) { - Style.paintImageContent(g2d, ((ImageProvider) value).getImage(), style, width, height, resolution); - } else if (value instanceof Image) { - Style.paintImageContent(g2d, (Image) value, style, width, height, resolution); - } else { - String var6 = Style.valueToText(value, style.getFormat()); - NewFormStyle.paintCellStyleString2(g2d, width, height, var6, style, resolution); - } - - } - } - - - private static boolean paintHighlightGroupMarkWhenExsit(Graphics2D g2d, TemplateCellElement cell, int left_up_count) { - if (cell.getHighlightGroup() != null && cell.getHighlightGroup().size() > 0) { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_HIGHT_LIGHT_MARK_COLOR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(0, 0); - polyline.lineTo(0, CELL_MARK_SIZE); - polyline.lineTo(CELL_MARK_SIZE, 0); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - return false; - } - - private static boolean paintPresentMarkWhenExsit(Graphics2D g2d, TemplateCellElement cell, int left_up_count) { - if (cell.getPresent() != null) { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_PRESENT_MARK_COLOR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(0 + left_up_count * CELL_MARK_SIZE, 0); - polyline.lineTo(0 + left_up_count * CELL_MARK_SIZE, 6); - polyline.lineTo(CELL_MARK_SIZE + left_up_count * CELL_MARK_SIZE, 0); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - return false; - } - - private static boolean paintPaginationMarkWhenExsit(Graphics2D g2d, TemplateCellElement cell, int width, int ringt_up_count) { - // 右上角: 标记是否有分页 - if (isRightTopMarker(cell)) { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_PAGINATION_MARK_COLOR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(width - 1 - ringt_up_count * CELL_MARK_SIZE, 0); - polyline.lineTo(width - 1 - ringt_up_count * CELL_MARK_SIZE, CELL_MARK_SIZE); - polyline.lineTo(width - 1 - (ringt_up_count + 1) * CELL_MARK_SIZE, 0); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - return false; - } - - private static boolean isRightTopMarker(TemplateCellElement cell) { - return cell.getCellPageAttr() != null && (cell.getCellPageAttr().isPageAfterColumn() - || cell.getCellPageAttr().isPageBeforeColumn() - || cell.getCellPageAttr().isPageAfterRow() - || cell.getCellPageAttr().isPageBeforeRow()); - } - - private static boolean paintResultMarkWhenExsit(Graphics2D g2d, Object value, int width, int ringt_up_count) { - //右上角标记是否自定义显示 - if (value instanceof DSColumn && ((DSColumn) value).getResult() != null) { - if (!ComparatorUtils.equals(((DSColumn) value).getResult(), "$$$")) { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_RESULT_MARK_COLOR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(width - ringt_up_count * CELL_MARK_SIZE - 1, 0); - polyline.lineTo(width - ringt_up_count * CELL_MARK_SIZE - 1, CELL_MARK_SIZE); - polyline.lineTo(width - (ringt_up_count + 1) * CELL_MARK_SIZE - 1, 0); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - } - - return false; - } - - private static void paintWidgetMarkWhenExsit(Graphics2D g2d, TemplateCellElement cell, int width, int height) { - // 右下角:是否填报, 设置为4时,三角太小了,不知何故,设置为6 - if (cell.getWidget() != null) { - Widget widget = cell.getWidget(); - Image img = ((ImageIcon) ReportUtils.createWidgetIcon(widget.getClass())).getImage(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.67f)); - g2d.drawImage(img, width - 15, height - 15, WIDGET_WIDTH, WIDGET_HEIGHT, null); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); - } - } - - private static void paintExpandMarkWhenExsit(Graphics2D g2d, TemplateCellElement cell) { - CellExpandAttr cellExpandAttr = cell.getCellExpandAttr(); - if (cellExpandAttr != null) { - if (cellExpandAttr.getDirection() == Constants.TOP_TO_BOTTOM) { - Paint oldPaint = g2d.getPaint(); - g2d.setPaint(CELL_DIRECTION_MARK_COLOR); - GraphHelper.drawLine(g2d, 2, 0, 2, 5); - GraphHelper.drawLine(g2d, 2, 5, 0, 2); - GraphHelper.drawLine(g2d, 2, 5, 4, 2); - g2d.setPaint(oldPaint); - } else if (cellExpandAttr.getDirection() == Constants.LEFT_TO_RIGHT) { - Paint oldPaint = g2d.getPaint(); - g2d.setPaint(CELL_DIRECTION_MARK_COLOR); - GraphHelper.drawLine(g2d, 0, 2, 5, 2); - GraphHelper.drawLine(g2d, 5, 2, 2, 0); - GraphHelper.drawLine(g2d, 5, 2, 2, 4); - g2d.setPaint(oldPaint); - } - } - } - - private static boolean paintDSColumnConditionmarkWhenExsit(Graphics2D g2d, Object value, int height, int left_dowm_count) { - // 左下角:数据列(DSColumn)相关:比如条件过滤 - if (value instanceof DSColumn && ((DSColumn) value).getCondition() != null) { - if (((DSColumn) value).getCondition() instanceof ListCondition && - ((ListCondition) ((DSColumn) value).getCondition()).getJoinConditionCount() == 0) { - // do nothing - } else { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_CONDITION_FILTER_MARK_COLOR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(0 + left_dowm_count * CELL_MARK_SIZE, height - 1); - polyline.lineTo((left_dowm_count + 1) * CELL_MARK_SIZE + 1, height - 1); - polyline.lineTo(0 + left_dowm_count * CELL_MARK_SIZE, height - 2 - CELL_MARK_SIZE); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - } - return false; - } - - private static boolean paintDSColumnParametermarkWhenExsit(Graphics2D g2d, Object value, int height, int left_dowm_count) { - // 左下角:动态注入参数 - if (value instanceof DSColumn && ((DSColumn) value).getParameters() != null) { - if (((DSColumn) value).getParameters().length > 0) { - Paint oldPaint = g2d.getPaint(); - - g2d.setPaint(CELL_PARAMETER_FILTER_MARK_CONLR); - GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); - polyline.moveTo(0 + left_dowm_count * CELL_MARK_SIZE, height - 1); - polyline.lineTo((left_dowm_count + 1) * CELL_MARK_SIZE + 1, height - 1); - polyline.lineTo(0 + left_dowm_count * CELL_MARK_SIZE, height - 2 - CELL_MARK_SIZE); - GraphHelper.fill(g2d, polyline); - - g2d.setPaint(oldPaint); - return true; - } - } - return false; - } - - /* - * 画悬浮元素 - * - * 仅根据宽度 + 高度画 - */ - //b:此方法在grid和tohtml的时候都被调用,所以对formula会有冲突,暂时这么改,应该考虑分开的,也可以根据result来判断,但是那么写好像不妥 - public static void paintFloatElement(Graphics2D g2d, FloatElement flotEl, int width, int height, int resolution) { - Style.paintBackground(g2d, flotEl.getStyle(), width, height); - - Object value = flotEl.getValue(); - if (value instanceof BaseFormula) { - value = ((BaseFormula) value).getContent(); - } - if (value instanceof BaseChartCollection) { - value = ((BaseChartCollection) value).createResultChartPainterWithOutDealFormula(Calculator.createCalculator(), WebChartIDInfo.createEmptyDesignerInfo(), width, height); - } - //图片需要切割一下 - if (value instanceof Image) { - value = CellUtils.value2ImageWithBackground(value, resolution, flotEl.getStyle(), width, height); - } - Style.paintContent(g2d, value, flotEl.getStyle(), width, height, resolution); - - Style.paintBorder(g2d, flotEl.getStyle(), width, height); - } - - /* - * 画悬浮元素flotEl - * - * 也就是画三个东西:背景 + 内容 + 边框 - */ - public static void paintFloatElement(Graphics2D g2d, FloatElement flotEl, Rectangle paintRectangle, Rectangle clipRectangle, int resolution) { - // 画悬浮元素的背景 - Style.paintBackground(g2d, flotEl.getStyle(), paintRectangle, clipRectangle); - - Object value = flotEl.getValue(); - if (value instanceof ResultChangeWhenExport) { - value = ((ResultChangeWhenExport) value).changeThis(); - } - // 画悬浮元素的内容 - Style.paintContent(g2d, value, resolution, flotEl.getStyle(), paintRectangle, clipRectangle); - // 画悬浮元素的边框 - Style.paintBorder(g2d, flotEl.getStyle(), paintRectangle, clipRectangle); - } - - public static void paintHTMLContent(Graphics2D g2d, String value, int resolution, Style style, Rectangle paintRectangle, Rectangle clipRectangle) { - Style.paintContent(g2d, createHTMLContentBufferedImage(value, paintRectangle, 0, 0, style), resolution, style, paintRectangle, clipRectangle); - } - - public static void paintTag(Painter painter, Repository repo, int width, int height, Style style, Tag tag) { - painter.paintTag(repo, width, height, style, tag); - } - - /** - * 如果用户希望以HTML方式展示String,这个时候先value变成图片 - * - * @param value 值 - * @param paintRectangle 绘制范围 - * @param x x坐标 - * @param y y坐标 - * @param style 当前格子样式 - * @return BufferedImage 返回图片. - */ - public static BufferedImage createHTMLContentBufferedImage(String value, Rectangle paintRectangle, int x, int y, Style style) { - return Html2ImageUtils.createHTMLContentBufferedImage(value, paintRectangle, x, y, style); - } - - /** - * see BaseUtils.getLineTextList, 等于BaseUtils.getLineTextList().size() - * Denny: 为了提高速度和性能,才单独拿出来的 - * TODO: 重构 - * - * @param text 文本 - * @param style 样式 - * @param paintWidth 单元格宽度 - * @return paintWidth 单位为PT - */ - public static int getLineTextCount(String text, Style style, UNIT paintWidth) { - if (style.getRotation() != 0) { - return 1; - } - - - if (style.getTextStyle() != Style.TEXTSTYLE_WRAPTEXT) { - return dealNotWrapTextCount(text.toCharArray()); - } else {// 自动换行 - return dealWrapTextCount(text, style, paintWidth); - } - } - - private static int dealNotWrapTextCount(char[] text_chars) { - boolean remain_chars = false; - int count = 0; - for (int t = 0; t < text_chars.length; t++) { - if (text_chars[t] == '\\') {// 判断是否是 "\n" - if (t + 1 < text_chars.length && text_chars[t + 1] == 'n') { - // 是"\n"字符串,但不是换行符. - t++; - count++; - if (remain_chars) { - remain_chars = false; - } - } else { - if (!remain_chars) { - remain_chars = true; - } - } - } else if (text_chars[t] == '\n' || (text_chars[t] == '\r' && t + 1 < text_chars.length - 1 && text_chars[t + 1] != '\n')) { - count++; - if (remain_chars) { - remain_chars = false; - } - } else { - if (!remain_chars) { - remain_chars = true; - } - } - } - - // 最后一个 - if (remain_chars) { - count++; - } - - return count; - } - - // 自动换行 - //neil:style里面, 默认值padding right = 2时, 默认不生效, 这边算行高时也不要计算入内 - //临时处理, 去掉左边框线, 因为浏览器计算时需要考虑左边框线宽度, 但这边还是存在问题的 - //同样需要考虑的是导出和web端展示, padding计算方式也不一致. - private static int dealWrapTextCount(String text, Style style, UNIT unitWidth) { - AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess(); - if (process != null) { - return process.getAutoChangeLineCount(text, new ObjectHolder(style), unitWidth); - } - int count = 0; - char[] text_chars = text.toCharArray(); - FontMetrics fontMetrics = getFontMetrics(style); - double paintWidth = unitWidth.toPixD(Constants.FR_PAINT_RESOLUTION); - double width = paintWidth - style.getPaddingLeft() - (style.getPaddingRight() == Style.DEFAULT_PADDING ? 0 : style.getPaddingRight()) - style.getBorderLeftWidth(); - boolean remain_lineText = false; - int lineTextWidth = 0; - int wordWidth = 0; - for (int t = 0, len = text_chars.length; t < len; t++) { - if (t != 0 && BaseUtils.isNumOrLetter(text_chars[t]) && BaseUtils.isNumOrLetter(text_chars[t - 1])) { - if (wordWidth + fontMetrics.charWidth(text_chars[t]) > width) { - if (lineTextWidth > 0) { - count++; - remain_lineText = false; - lineTextWidth = 0; - } - count++; - wordWidth = 0; - } - wordWidth += fontMetrics.charWidth(text_chars[t]); - } else if (isSwitchLine(text_chars, t) || isLN(text_chars, t)) {// 判断是否是 "\n" - if (isLN(text_chars, t)) { - t++;// 忽略'n'字符.// 是"\n"字符串,但不是换行符,依然需要换行. - } - if (lineTextWidth + wordWidth > width && remain_lineText) { - count += 2; - } else { - count++; - } - remain_lineText = false; - lineTextWidth = 0; - wordWidth = 0; - } else { - if (text_chars[t] == '\\' && t + 1 < text_chars.length && text_chars[t + 1] == '\\') {// 判断是否是转义字符'\' - t++;// _denny: 增加了转义字符'\\'用来表示\,使"\n"可以输入 - } - if (lineTextWidth + wordWidth > width && remain_lineText) { - count++; - lineTextWidth = isPunctuationAtLineHead(t, text_chars) ? dealLineWidthWithPunctuation(t, text_chars, fontMetrics) : 0; - } - remain_lineText = true; - lineTextWidth += wordWidth; - wordWidth = fontMetrics.charWidth(text_chars[t]); - } - } - if (lineTextWidth + wordWidth > width && remain_lineText) { - count += 2; - } else { - count++; - } - return count; - } - - /** - * 标点符号是否在换行后的行首 - */ - private static boolean isPunctuationAtLineHead(int t, char[] text_chars) { - if (t > 1 && BaseUtils.isPunctuation(text_chars[t - 1])) { - return true; - } - return false; - } - - /** - * 防止有连续多个标点符号,要找一个非标点符号字符 - * - * @date 2014-4-17 - */ - private static int dealLineWidthWithPunctuation(int t, char[] text_chars, FontMetrics fontMetrics) { - if (t < 2) { - return 0; - } - int lineWidth = 0; - for (int index = t - 2; index >= 0; index--) { - lineWidth += fontMetrics.charWidth(text_chars[index]); - if (!BaseUtils.isPunctuation(text_chars[index])) { - break; - } - } - return lineWidth; - } - - private static boolean isSwitchLine(char[] text_chars, int t) { - return text_chars[t] == '\n' || (text_chars[t] == '\r' && t + 1 < text_chars.length - 1 && text_chars[t + 1] != '\n'); - } - - private static boolean isLN(char[] text_chars, int t) { - return text_chars[t] == '\\' && t + 1 < text_chars.length && text_chars[t + 1] == 'n'; - } - - /** - * Gets the preferred width. - */ - public static UNIT getPreferredWidth(CellElement cell, UNIT height) { - if (cell == null) { - return UNIT.ZERO; - } - - Object value = cell.getShowValue(); - // 只接受Text,Number,和SeparatorPainter - // got the text - if (value instanceof BaseFormula) { - if (((BaseFormula) value).getResult() != null) { - value = ((BaseFormula) value).getResult(); - } else { - value = StringUtils.EMPTY; - } - } - Style style = cell.getStyle(); - if (style == null) { - style = Style.DEFAULT_STYLE; - } - CellGUIAttr cg = cell.getCellGUIAttr() == null ? new CellGUIAttr() : cell.getCellGUIAttr(); - value = Utils.resolveOtherValue(value, cg.isShowAsImage(), PresentationType.EXPORT); - String text = Style.valueToText(value, style.getFormat()); - - FontMetrics cellFM = getFontMetrics(style); - //bug 12151 有边框线的单元格 自动调整列宽 会多一行 - UNIT padding = new PT(style.getPaddingLeft() + style.getPaddingRight()); - - if (cg.isShowAsHTML()) { - return Html2ImageUtils.getHtmlWidth(text, height, style); - } - - return FU.valueOfPix(cellFM.stringWidth(text) + UNIT_SIZE, Constants.FR_PAINT_RESOLUTION).add(padding); - } - - private static FontMetrics getFontMetrics(Style style) { - Font font = style.getFRFont().applyResolutionNP(Constants.FR_PAINT_RESOLUTION); - FontProcessor processor = ExtraClassManager.getInstance().getSingle(FontProcessor.MARK_STRING); - if (processor != null) { - font = processor.readExtraFont(font); - } - return GraphHelper.getFontMetrics(font); - } - - /** - * Preferred height. (Got the shrink preferred height of CellElement). - * 单位格的预计算高度 - * - * @param cellElement 单元格内容 - * @param paintWidth 画的宽度 - * @return UNIT 单位 - */ - public static UNIT analyzeCellElementPreferredHeight(CellElement cellElement, UNIT paintWidth) { - // 计算高度用显示值 - Object value = cellElement.getShowValue(); - // 只接受Text,Number,和SeparatorPainter - Style style = cellElement.getStyle(); - // got the text - if (value instanceof BaseFormula) { - if (((BaseFormula) value).getResult() != null) { - value = ((BaseFormula) value).getResult(); - } else { - value = StringUtils.EMPTY; - } - } - CellGUIAttr cg = cellElement.getCellGUIAttr() == null ? new CellGUIAttr() : cellElement.getCellGUIAttr(); - if (!(value instanceof String) && !(value instanceof Integer)) { - value = DataUtils.resolveOtherValue(value, cg.isShowAsImage(), cg.isShowAsDownload(), null, true); - } - String text = Style.valueToText(value, style.getFormat()); - - if (cg.isShowAsHTML()) { - return Html2ImageUtils.getHtmlHeight(text, paintWidth, style); - } - - return PaintUtils.analyzeCellElementPreferredHeight(text, style, paintWidth, cg.isShowAsHTML()); - } - - /** - * 单位格的预计算高度 - * 单位PT - * - * @param text 文本 - * @param style 格式 - * @param paintWidth 画的宽度 - * @param isShowAsHtml 是否以html展示 - * @return 返回 单位 - */ - private static UNIT analyzeCellElementPreferredHeight(String text, Style style, UNIT paintWidth, boolean isShowAsHtml) { - if (style == null) { - //peter:获取默认的Style. - style = Style.DEFAULT_STYLE; - } - - // got the text - if (text == null || text.length() <= 0) { - return PT.valueOf(0); - } - - // 变成Line Text List. - if (style.getRotation() != 0) { // more easy to paint. - // attribute map. - return PT.valueOf((float) GraphHelper.stringDimensionWithRotation(text, style.getFRFont(), -style.getRotation(), - CoreConstants.DEFAULT_FRC).getHeight()); - } - // 先获得FontMetics. - int lineCount = getLineTextCount(text, style, paintWidth); - AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess(); - if (process != null) { - //算了这两个接口分开做 - return process.getLinedTextHeight(lineCount, new ObjectHolder(style)); - } - - // carl:和paint那边一致,添上段前段后和行间距 - PT lineSpacing = PT.valueOf(style.getSpacingAfter() + style.getSpacingBefore() + style.getLineSpacing() * lineCount); - FontMetrics fontMetrics = getFontMetrics(style); - int textHeight = fontMetrics.getHeight(); - FU allTextHeight = FU.valueOfPix(textHeight * lineCount, Constants.FR_PAINT_RESOLUTION); - return lineSpacing.add(allTextHeight);// 需要给底部添加Leading. - } - - /** - * 截取文字,只考虑了垂直方向,水平方向没意义且难度大. - * - * @param value 画的值 - * @param style 字体样式格式. - * @param blockArea 冻结的范围 - * @param resolution 分辨率 - * @return 返回的字符串 - */ - public static String clipBlockValue(Object value, Style style, Rectangle primitiveArea, Rectangle blockArea, int resolution, boolean isShowAsHTML) { - if (value == null) { - return null; - } - if (value instanceof BaseFormula) { - value = ((BaseFormula) value).getResult(); - } - if (blockArea.y >= primitiveArea.height || blockArea.y + blockArea.height <= 0) { - return null; - } - //截取位置,相对于clipArea - int startY = blockArea.y > 0 ? blockArea.y : 0; - int endY = blockArea.y + blockArea.height < primitiveArea.height ? blockArea.y + blockArea.height : primitiveArea.height; - if (blockArea.x >= primitiveArea.width || blockArea.x + blockArea.width <= 0) { - return null; - } - if (isShowAsHTML) { - return Html2ImageUtils.clipHtmlContent(value, style, primitiveArea, resolution, startY, endY); - } - List lineList = BaseUtils.getLineTextList((String) value, style, style.getFRFont().applyResolutionNP(resolution), primitiveArea.width, resolution); - if (lineList.isEmpty()) { - return null; - } - double spacingBefore = PT.pt2pix(style.getSpacingBefore(), resolution); - double spacingAfter = PT.pt2pix(style.getSpacingAfter(), resolution); - double lineSpacing = PT.pt2pix(style.getLineSpacing(), resolution); - double lineHeight = lineSpacing + GraphHelper.getFontMetrics(style.getFRFont().applyResolutionNP(resolution)).getHeight(); - int textAllHeight = (int) (lineHeight * lineList.size() + spacingBefore + spacingAfter); - //第一行文字距区域高度 - int textStartY = (int) spacingBefore; - - if (style.getVerticalAlignment() == Constants.BOTTOM) { - textStartY += (primitiveArea.height - textAllHeight); - } - if (endY <= textStartY || startY >= textStartY + lineHeight * lineList.size()) { - return null; - } - int lineStart = getLineStart(lineList, lineHeight, textStartY, startY);//截取区域起始行 - int lineEnd = getLineEnd(lineList, lineHeight, endY, textStartY);//截取区域结束行 - String text = ""; - for (; lineStart <= lineEnd; lineStart++) { - text += lineList.get(lineStart); - } - return text; - } - - private static int getLineStart(List lineList, double lineHeight, int textStartY, int startY) { - int lineStart = 0; - for (int i = 0; i < lineList.size(); i++) { - if (textStartY + lineHeight * (i) <= startY && textStartY + lineHeight * (i + 1) > startY) {//压线 - if (startY - textStartY - lineHeight * (i) > lineHeight / 2) { - lineStart = i + 1; - } else { - lineStart = i; - } - } - } - return lineStart; - } - - private static int getLineEnd(List lineList, double lineHeight, int endY, int textStartY) { - int lineEnd = lineList.size() - 1; - for (int i = 0; i < lineList.size(); i++) { - if (textStartY + lineHeight * (i) < endY && textStartY + lineHeight * (i + 1) >= endY) {//压线 - //neil:仿宋,12号字, 行间距8为例, 转为px的行间距大小为10.666, 这边算出的应该有31.98行, 因此要进位 - if (endY - textStartY - lineHeight * (i) >= lineHeight / 2) { - lineEnd = i; - } else { - lineEnd = i - 1; - } - } - } - return lineEnd; - } - - /** - * paintBarcode - */ - public static void paintBarcode(Graphics2D g2d, int width, int height, String text, Style style, BarcodeAttr barcodeAttr) { - BarcodeImpl barcodeImpl; - try { - barcodeImpl = BarCodeUtils.getBarcodeImpl(barcodeAttr, text); - } catch (BarcodeException exp) { - try { - //设置默认值. - barcodeImpl = BarCodeUtils.getBarcodeImpl(new BarcodeAttr(), null); - } catch (BarcodeException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - return; - } - } - - //字体 - if (style.getFRFont() != null) { - barcodeImpl.setFont(style.getFRFont()); - barcodeImpl.setForeground(style.getFRFont().getForeground()); - } - //背景 - Background background = style.getBackground(); - if (background != null && background instanceof ColorBackground) { - barcodeImpl.setBackground(((ColorBackground) background).getColor()); - } - - //根据宽度和高度来确定起始点 - int pointX = (width - barcodeImpl.getWidth()) / 2; - int pointY = (height - barcodeImpl.getHeight()) / 2; - - barcodeImpl.draw(g2d, pointX, pointY); - } - - /** - * create font attribute map, 创建属性map - * - * @param font 字体 - * @return map 返回字体创建的Map - */ - public static Map createFontAttributeMap(Font font) { - Map returnFontAttributeMap = (Map) fontAttributeMapCache.get(font); - if (returnFontAttributeMap == null) {// create - // returnFontAttributeMap. - returnFontAttributeMap = font.getAttributes(); - fontAttributeMapCache.put(font, returnFontAttributeMap); - } - - if (font instanceof FRFont) { - FRFont frFont = (FRFont) font; - - // Strikethrough - if (frFont.isStrikethrough()) { - returnFontAttributeMap.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); - } - } - - return returnFontAttributeMap; - } - -} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java index cb415df59..47512348f 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java @@ -1,30 +1,16 @@ package com.fr.design.fit.common; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteBodyLayout; -import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.MutilTempalteTabPane; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.fit.JFormType; import com.fr.design.fit.NewJForm; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.FormArea; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; import com.fr.event.Event; import com.fr.event.Listener; import com.fr.file.MemFILE; import com.fr.file.StashedFILE; import com.fr.form.fit.common.LightTool; -import com.fr.form.fit.NewFormMarkAttr; -import com.fr.form.ui.Widget; -import com.fr.form.ui.widget.CRBoundsWidget; import com.fr.general.ComparatorUtils; - -import java.awt.Rectangle; import java.util.List; /** @@ -33,31 +19,20 @@ import java.util.List; * @create: 2020/09/03 14:19 */ public class TemplateTool { - //和转换有关的所有代码都在这个监听器中 - //在判断新老模式时,统一使用FormUIModeConfig.getInstance().newUIMode()进行判断 - private static Listener switchListener = new Listener() { + private static final Listener switchListener = new Listener() { @Override public void on(Event event, JTemplate jTemplate) { - if (!(jTemplate instanceof JForm)) { - JFormType.OLD_TYPE.switchUIMode(); - return; - } - JFormType currentType = JFormType.OLD_TYPE; - if (AdaptiveSwitchUtil.isSwitchJFromIng()) { - currentType = DesignerUIModeConfig.getInstance().newUIMode() ? JFormType.NEW_TYPE : JFormType.OLD_TYPE; - } else if (isNewJForm(jTemplate)) { - currentType = JFormType.NEW_TYPE; - } - //UI转换 - currentType.switchUIMode(); - //标志位转换 - currentType.updateJFromTemplateType(jTemplate); - //预览方式转换 - currentType.updatePreviewType(jTemplate); + jTemplate.setDesignerUIMode(); } }; - private static boolean isNewJForm(JTemplate jTemplate) { + + public static Listener getSwitchListener() { + return switchListener; + } + + + public static boolean isNewJForm(JTemplate jTemplate) { if (jTemplate instanceof NewJForm) { NewJForm newJForm = (NewJForm) jTemplate; if (LightTool.containNewFormFlag(newJForm.getTarget()) || newJForm.getTarget().getTemplateID() == null) { @@ -67,8 +42,8 @@ public class TemplateTool { return false; } - public static Listener getSwitchListener() { - return switchListener; + public static boolean isCurrentEditingNewJForm(){ + return isNewJForm(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); } /** @@ -79,8 +54,7 @@ public class TemplateTool { * @date: 2020/9/6 14:17 */ public static JTemplate getCurrentEditingTemplate() { - JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - return jTemplate; + return HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); } /** @@ -168,55 +142,7 @@ public class TemplateTool { jTemplate.requestFocus(); } - /** - * @param height - * @param width - * @param newJForm - * @Description: 只改变绝对布局body的尺寸 - * @return: - * @Author: Henry.Wang - * @date: 2020/9/11 15:14 - */ - public static void onlyChangeAbsoluteBodySize(int height, int width, NewJForm newJForm) { - FormDesigner formDesigner = newJForm.getFormDesign(); - FormArea formArea = formDesigner.getArea(); - XLayoutContainer root = formDesigner.getRootComponent(); - XWAbsoluteBodyLayout xwAbsoluteBodyLayout = LayoutTool.getXWAbsoluteBodyLayout(newJForm); - if (root.acceptType(XWFitLayout.class) && xwAbsoluteBodyLayout != null) { - XWFitLayout layout = (XWFitLayout) root; - if (height == layout.toData().getContainerHeight() && width == layout.toData().getContainerWidth()) - return; - formArea.setWidthPaneValue(width); - formArea.setHeightPaneValue(height); - layout.setSize(width, height); - xwAbsoluteBodyLayout.setSize(width, height); - Widget widget = layout.toData().getWidget(0); - if (widget instanceof CRBoundsWidget) { - ((CRBoundsWidget) widget).setBounds(new Rectangle(0, 0, width, height)); - } - layout.toData().setContainerWidth(width); - layout.toData().setContainerHeight(height); - formArea.doReCalculateRoot(width, height, layout); - } - formDesigner.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_EDITED); - } - /** - * @param newJForm - * @Description: 因为新老模板切换有截断的问题,所以body的尺寸会在调用onlyChangeAbsoluteBodySize之后发生改变。为了使模板文件中的尺寸不发生,要在模板保存时调用此函数 - * @return: - * @Author: Henry.Wang - * @date: 2020/9/11 15:20 - */ - public static void resetAbsoluteBodySize(NewJForm newJForm) { - if (LayoutTool.absoluteLayoutForm(newJForm)) { - NewFormMarkAttr newFormMarkAttr = newJForm.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG); - XLayoutContainer root = newJForm.getFormDesign().getRootComponent(); - if (newFormMarkAttr != null && root instanceof XWFitLayout) { - ((XWFitLayout) root).toData().setContainerWidth(newFormMarkAttr.getBodyWidth()); - ((XWFitLayout) root).toData().setContainerHeight(newFormMarkAttr.getBodyHeight()); - } - } - } + } diff --git a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java index ed94eadb4..3afe61253 100644 --- a/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java +++ b/designer-form/src/main/java/com/fr/design/fit/toolbar/SwitchAction.java @@ -3,7 +3,8 @@ package com.fr.design.fit.toolbar; import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.TemplateTreePane; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.JForm; import com.fr.design.fit.NewJForm; import com.fr.design.fit.common.AdaptiveSwitchUtil; import com.fr.design.fit.common.TemplateTool; @@ -11,7 +12,6 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.BaseJForm; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.MenuKeySet; import com.fr.design.utils.LoadingUtils; @@ -62,11 +62,11 @@ public class SwitchAction extends UpdateAction { } }; - public SwitchAction() { - initMenuStyle(); + public SwitchAction(JForm jForm) { + initMenuStyle(jForm); } - private void initMenuStyle() { + private void initMenuStyle(JForm jForm) { this.setMenuKeySet(SWITCH_ATTR); this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); @@ -78,7 +78,7 @@ public class SwitchAction extends UpdateAction { Font oldFont = switchBtn.getFont(); switchBtn.setFont(new Font(oldFont.getName(),oldFont.getStyle(),12)); switchBtn.setForeground(new Color(0x33, 0x33, 0x34)); - freshSwitchButton(); + freshSwitchButton(jForm); } @Override @@ -90,11 +90,7 @@ public class SwitchAction extends UpdateAction { if (confirmSwitchDialog() && backUpOldModeJTemplate()) { AdaptiveSwitchUtil.setSwitchJFromIng(1); showLoadingJPanel(); - if (DesignerUIModeConfig.getInstance().newUIMode()) { - AdaptiveSwitchUtil.switch2OldUI(); - } else { - AdaptiveSwitchUtil.switch2NewUI(); - } + AdaptiveSwitchUtil.switchReload(); } } @@ -171,7 +167,7 @@ public class SwitchAction extends UpdateAction { */ private boolean backUpOldModeJTemplate() { JTemplate jTemplate = TemplateTool.getCurrentEditingTemplate(); - if (jTemplate != null && !DesignerUIModeConfig.getInstance().newUIMode()) { + if (jTemplate != null && !TemplateTool.isNewJForm(jTemplate)) { FILE editingFILE = jTemplate.getEditingFILE(); if (editingFILE != null && editingFILE.exists()) { try { @@ -233,7 +229,7 @@ public class SwitchAction extends UpdateAction { * @date: 2020/9/18 11:20 */ private boolean confirmSwitchDialog() { - Object message = DesignerUIModeConfig.getInstance().newUIMode() ? Toolkit.i18nText("Fine-Designer_Fit_Confirm_New_Old_Switch") : Toolkit.i18nText("Fine-Designer_Fit_Confirm_Old_New_Switch"); + Object message = TemplateTool.isCurrentEditingNewJForm() ? Toolkit.i18nText("Fine-Designer_Fit_Confirm_New_Old_Switch") : Toolkit.i18nText("Fine-Designer_Fit_Confirm_Old_New_Switch"); int returnVal = FineJOptionPane.showConfirmDialog( DesignerContext.getDesignerFrame(), message, @@ -265,8 +261,8 @@ public class SwitchAction extends UpdateAction { * @Author: Henry.Wang * @date: 2020/8/31 16:39 */ - public UIButton freshSwitchButton() { - if (DesignerUIModeConfig.getInstance().newUIMode()) { + public UIButton freshSwitchButton(JForm jForm) { + if (TemplateTool.isNewJForm(jForm)) { switchBtn.setToolTipText(Toolkit.i18nText("Fine-Designer_Fit_Switch_To_Old_UI")); switchBtn.setText(Toolkit.i18nText("Fine-Designer_Fit_Switch_To_Old_Version")); } else { @@ -277,7 +273,7 @@ public class SwitchAction extends UpdateAction { } public UIButton getToolBarButton() { - return freshSwitchButton(); + return switchBtn; } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormArea.java b/designer-form/src/main/java/com/fr/design/mainframe/FormArea.java index be001e881..d989aae21 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormArea.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormArea.java @@ -7,7 +7,6 @@ import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWBorderLayout; import com.fr.design.designer.creator.XWFitLayout; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButtonUI; import com.fr.design.gui.ilable.UILabel; @@ -25,11 +24,11 @@ import com.fr.design.scrollruler.VerticalRuler; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.design.utils.gui.LayoutUtils; -import com.fr.form.fit.NewFormMarkAttr; import com.fr.form.main.mobile.FormMobileAttr; import com.fr.form.ui.container.WBodyLayoutType; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WFitLayout; +import com.fr.general.FRScreen; import com.fr.general.IOUtils; import com.fr.stable.AssistUtils; @@ -66,12 +65,10 @@ import java.awt.event.MouseWheelEvent; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; public class FormArea extends JComponent implements ScrollRulerComponent { - private static final double SLIDER_FLOAT = 400.0; - private static final double SLIDER_MIN = 10.0; private static final String SCALE_PLUS_COMMAND = "scale_plus"; private static final String SCALE_MINUS_COMMAND = "scale_minus"; public static final String FIX_LAYOUT_SWITCH_BUTTON = "fix_layout_switch_button"; - public static final double DEFAULT_SLIDER = 100.0; + public static final double DEFAULT_SLIDER = 100.0D; private static final int ROTATIONS = 50; public static final int SHOWVALMAX = 400; public static final int SHOWVALMIN = 10; @@ -90,21 +87,9 @@ public class FormArea extends JComponent implements ScrollRulerComponent { private UINumberField heightPane; private JFormSliderPane slidePane; private boolean isValid = true; - // 初始时滑块值为100,托动后的值设为START_VALUE; - private double START_VALUE = DEFAULT_SLIDER; - private double screenValue; private UIButton fixLayoutSwitchButton; private boolean isFixLayoutEditState; - - public FormScrollBar getHorScrollBar() { - return horScrollBar; - } - - public void setHorScrollBar(FormScrollBar horScrollBar) { - this.horScrollBar = horScrollBar; - } - public FormArea(FormDesigner designer) { this(designer, true); } @@ -243,7 +228,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent { heightPane.setPreferredSize(new Dimension(60, 0)); slidePane = JFormSliderPane.getInstance(); - JPanel resizePane = TableLayoutHelper.createCommonTableLayoutPane( new JComponent[][]{{tipsPane, layoutSwitchPane, widthPane, new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Indent_Pixel")), @@ -258,6 +242,7 @@ public class FormArea extends JComponent implements ScrollRulerComponent { slidePane.setVisible(true); initCalculateSize(); slidePane.addValueChangeListener(showValSpinnerChangeListener); + slidePane.setShowValue(FRScreen.getFRScreenByDimension(Toolkit.getDefaultToolkit().getScreenSize()).getValue().intValue()); } public void undoFixLayoutState(boolean isFixLayout) { @@ -309,41 +294,10 @@ public class FormArea extends JComponent implements ScrollRulerComponent { this.designer.repaint(); } - - /** - * 返回当前的屏幕分辨率对应的百分比值 - * - * @return 缩放的百分比值 - */ - public double getScreenValue() { - return screenValue; - } - - /** - * 设置屏幕分辨率对应的百分比值 - * - * @param screenValue 百分比值 - */ - public void setScreenValue(double screenValue) { - this.screenValue = screenValue; - } - private void initCalculateSize() { - Toolkit toolkit = Toolkit.getDefaultToolkit(); - Dimension scrnsize = toolkit.getScreenSize(); - this.screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(scrnsize).getValue(); XLayoutContainer root = FormArea.this.designer.getRootComponent(); - // 7.1.1不放缩放滑块,但表单大小仍按屏幕分辨率调整 -// slidePane.populateBean(screenValue); if (root.acceptType(XWFitLayout.class)) { - XWFitLayout layout = (XWFitLayout) root; - if ( !AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) { - reCalculateRoot(screenValue, true); - } else { - // 组件间隔啊 - // REPORT-2585 原有的逻辑导致嵌套的tab中的间隔加不上去,会在后续拖动的过程中出问题 - reCalculateDefaultRoot(screenValue, true); - } + reCalculateDefaultRoot(); } LayoutUtils.layoutContainer(root); updateCreatorsBackupBound(root); @@ -380,18 +334,10 @@ public class FormArea extends JComponent implements ScrollRulerComponent { // 失去焦点时,可以认为输入结束 int width = (int) ((UINumberField) e.getSource()).getValue(); changeWidthPaneValue(width); - changeFormMarkAttrWidth(width); } }); } - private void changeFormMarkAttrWidth(int width) { - NewFormMarkAttr newFormMarkAttr = designer.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG); - if (newFormMarkAttr != null) { - newFormMarkAttr.setBodyWidth(width); - } - } - private void changeWidthPaneValue(int width) { XWFitLayout layout = (XWFitLayout) designer.getRootComponent(); @@ -407,7 +353,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent { public void actionPerformed(ActionEvent evt) { int height = (int) ((UINumberField) evt.getSource()).getValue(); changeHeightPaneValue(height); - changeFormMarkAttrHeight(height); } }); heightPane.addFocusListener( @@ -420,13 +365,6 @@ public class FormArea extends JComponent implements ScrollRulerComponent { }); } - private void changeFormMarkAttrHeight(int height){ - NewFormMarkAttr newFormMarkAttr = designer.getTarget().getAttrMark(NewFormMarkAttr.XML_TAG); - if (newFormMarkAttr != null) { - newFormMarkAttr.setBodyHeight(height); - } - } - private void changeHeightPaneValue(int height) { XWFitLayout layout = (XWFitLayout) designer.getRootComponent(); @@ -497,78 +435,26 @@ public class FormArea extends JComponent implements ScrollRulerComponent { * 修改大小后,再根据屏幕分辨率调整下 */ public void doReCalculateRoot(int width, int height, XWFitLayout layout) { -// double value = slidePane.updateBean(); - //重置滑块的值为默认值100 - START_VALUE = DEFAULT_SLIDER; - if ( AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) { - layout.getParent().setSize(width, height + designer.getParaHeight()); - FormArea.this.validate(); - } else { - layout.setBackupGap(screenValue / DEFAULT_SLIDER); - reCalculateRoot(screenValue, false); - } - } - - /** - * 按照界面大小的百分比值调整root大小 - * - * @param needCalculateParaHeight 是否需要调整参数界面高度 - * @param value - */ - private void reCalculateRoot(double value, boolean needCalculateParaHeight) { - if ( AssistUtils.equals(value, START_VALUE) ) { - return; - } - double percent = (value - START_VALUE) / START_VALUE; - XLayoutContainer root = FormArea.this.designer.getRootComponent(); - if (root.acceptType(XWFitLayout.class)) { - XWFitLayout layout = (XWFitLayout) root; - layout.setContainerPercent(value / DEFAULT_SLIDER); - traverAndAdjust(layout, percent); - layout.adjustCreatorsWhileSlide(percent); - - // 拖动滑块,先将内部组件百分比大小计算,再计算容器大小 - - Dimension d = new Dimension(layout.getWidth(), layout.getHeight()); - // 自适应布局的父层是border - if (layout.getParent() != null) { - int paraHeight = designer.getParaHeight(); - if (needCalculateParaHeight && paraHeight > 0) { - designer.setParaHeight(paraHeight); - XWBorderLayout parent = (XWBorderLayout) layout.getParent(); - parent.toData().setNorthSize(paraHeight); - parent.removeAll(); - parent.add(designer.getParaComponent(), WBorderLayout.NORTH); - parent.add(designer.getRootComponent(), WBorderLayout.CENTER); - } - layout.getParent().setSize(d.width, d.height + paraHeight); - // 调整自适应布局大小后,同步调整参数界面和border大小,此时刷新下formArea - FormArea.this.validate(); - } - START_VALUE = value; - } + layout.getParent().setSize(width, height + designer.getParaHeight()); + FormArea.this.validate(); } /** * 按照界面大小的百分比值调整root大小 * - * @param needCalculateParaHeight 是否需要调整参数界面高度 - * @param value */ - private void reCalculateDefaultRoot(double value, boolean needCalculateParaHeight) { + private void reCalculateDefaultRoot() { XLayoutContainer root = FormArea.this.designer.getRootComponent(); if (root.acceptType(XWFitLayout.class)) { XWFitLayout layout = (XWFitLayout) root; - layout.setContainerPercent(1.0); traverAndAdjust(layout, 0.0); layout.adjustCreatorsWhileSlide(0.0); // 拖动滑块,先将内部组件百分比大小计算,再计算容器大小 - Dimension d = new Dimension(layout.getWidth(), layout.getHeight()); // 自适应布局的父层是border if (layout.getParent() != null) { int paraHeight = designer.getParaHeight(); - if (needCalculateParaHeight && paraHeight > 0) { + if (paraHeight > 0) { designer.setParaHeight(paraHeight); XWBorderLayout parent = (XWBorderLayout) layout.getParent(); parent.toData().setNorthSize(paraHeight); @@ -885,16 +771,11 @@ public class FormArea extends JComponent implements ScrollRulerComponent { heightPane.setValue(height); reCalculateHeight((int) height); } - if (designer.getRootComponent().acceptType(XWFitLayout.class) && AssistUtils.equals(screenValue, DEFAULT_SLIDER) ) { + if (designer.getRootComponent().acceptType(XWFitLayout.class) ) { XWFitLayout layout = (XWFitLayout) designer.getRootComponent(); // 撤销时先refreshRoot了,此处去掉内边距再增加间隔 layout.moveContainerMargin(); layout.addCompInterval(layout.getAcualInterval()); - } else if (designer.getRootComponent().acceptType(XWFitLayout.class)) { - START_VALUE = DEFAULT_SLIDER; - reCalculateRoot(screenValue, true); -// slidePane.populateBean(slide); - } this.slidePane.setShowValue((int) slide); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index 3eb40b6a2..adc59581a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -43,7 +43,6 @@ import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.event.DesignerOpenedListener; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.fun.RightSelectionHandlerProvider; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; @@ -151,7 +150,6 @@ public class FormDesigner extends TargetComponent

implements TreeSelection // 存储被选择组件和剪切板的model private transient SelectionModel selectionModel; - private int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); // 编辑状态的事件表 private CreatorEventListenerTable edit; protected List designerActions; @@ -1801,14 +1799,6 @@ public class FormDesigner extends TargetComponent implements TreeSelection } - public void setResolution(int resolution) { - this.resolution = resolution; - } - - public int getResolution() { - return this.resolution; - } - public double getScale() { return scale; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java index 9284554dc..aab1b27b7 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe; import com.fr.base.GraphHelper; +import com.fr.base.ScreenResolution; import com.fr.base.Utils; import com.fr.base.iofile.attr.WatermarkAttr; import com.fr.base.vcs.DesignerMode; @@ -132,7 +133,7 @@ public class FormDesignerUI extends ComponentUI { return; } WatermarkAttr watermark = ReportUtils.getWatermarkAttrFromTemplateAndGlobal(designer.getTarget()); - WatermarkPainter painter = WatermarkPainter.createPainter(watermark, designer.getResolution()); + WatermarkPainter painter = WatermarkPainter.createPainter(watermark, ScreenResolution.getScreenResolution()); painter.paint(g, 0, 0, designer.getArea().getBounds()); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java index 7d3b17f5b..5e5740f03 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormSelectionUtils.java @@ -182,11 +182,10 @@ public class FormSelectionUtils { if (!childrenList.isEmpty()) { for (Object aChildrenList : childrenList) { XWTabFitLayout tabLayout = (XWTabFitLayout) aChildrenList; - double percent = tabLayout.getContainerPercent(); Component[] components = tabLayout.getComponents(); for (Component component : components) { Rectangle show = component.getBounds(); - component.setBounds(new Rectangle((int) (show.x * percent), (int) (show.y * percent), (int) (show.width * percent), (int) (show.height * percent))); + component.setBounds(new Rectangle(show.x, show.y, show.width, show.height)); } } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index 247463ff8..8d2748eb3 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -71,6 +71,8 @@ import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.utils.gui.LayoutUtils; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; +import com.fr.file.FileNodeFILE; +import com.fr.file.filetree.FileNode; import com.fr.file.filter.ChooseFileFilter; import com.fr.form.FormElementCaseContainerProvider; import com.fr.form.FormElementCaseProvider; @@ -1224,4 +1226,17 @@ public class JForm extends JTemplate implements BaseJForm { public RootDesignDefinePane(XCreator xCreator) { super(xCreator); - newForm = TemplateTool.getCurrentEditingNewJForm() != null && DesignerUIModeConfig.getInstance().newUIMode(); + newForm = TemplateTool.getCurrentEditingNewJForm() != null && DesignerUIModeConfig.getInstance().simulateWebUIMode(); this.root = (XWParameterLayout) xCreator; initComponent(); } diff --git a/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java b/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java index cb04f9345..782538f63 100644 --- a/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java +++ b/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java @@ -45,6 +45,7 @@ public class DeveloperPreview extends AbstractPreviewProvider { public void onClick(JTemplate jt) { super.onClick(jt); MutilTempalteTabPane.getInstance().closeCurrentTpl(); + jt.generateForBiddenTemplate(); } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java index f711eb157..85265fa6e 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java @@ -150,7 +150,7 @@ public class WidgetBoundPane extends BasicPane { public void limitWidth(WLayout wabs, int w, Rectangle bounds, Rectangle rec) { int difference = 0; - int minWidth = (int) (MINWIDTH * ((WFitLayout) wabs).getResolutionScaling()); + int minWidth = MINWIDTH; PaddingMargin margin = wabs.getMargin(); if (bounds.width != w) { if (bounds.width == rec.width - margin.getLeft() - margin.getRight()) { @@ -172,7 +172,7 @@ public class WidgetBoundPane extends BasicPane { public void limitHeight(WLayout wabs, int h, Rectangle bounds, Rectangle rec) { int difference = 0; PaddingMargin margin = wabs.getMargin(); - int minHeight = (int) (MINHEIGHT * ((WFitLayout) wabs).getResolutionScaling()); + int minHeight = MINHEIGHT; if (bounds.height != h) { if (bounds.height == rec.height - margin.getTop() - margin.getBottom()) { FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds")); diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java index 9507248df..3eb947488 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/ElementEditorDefinePane.java @@ -5,7 +5,7 @@ import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedComponentStyle; import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.*; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.fit.common.TemplateTool; import com.fr.design.fit.attrpane.PcFitExpandablePane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.style.FollowingThemePane; @@ -76,7 +76,7 @@ public class ElementEditorDefinePane extends WTitleLayoutDefinePane list = new ArrayList(); @@ -102,7 +102,7 @@ public class ElementEditorDefinePane extends WTitleLayoutDefinePane buttonGroup; + private MobileTextFieldInputSettingPane settingPane; public ScanCodeMobileDefinePane(XCreator xCreator) { this.xCreator = xCreator; @@ -27,39 +25,11 @@ public class ScanCodeMobileDefinePane extends MobileWidgetDefinePane { @Override public void initPropertyGroups(Object source) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - JPanel mobileSettingsPane = getMobileSettingsPane(); - this.add(mobileSettingsPane, BorderLayout.NORTH); + settingPane = new MobileTextFieldInputSettingPane(); + this.add(new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, settingPane), BorderLayout.NORTH); this.repaint(); } - private UIExpandablePane getMobileSettingsPane() { - JPanel panel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 10); - buttonGroup = new ModeButtonGroup<>(); - UIRadioButton scanCodeAndManualInput = new UIRadioButton( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design__Mobile_Support_Scan_Code_And_Manual_Input"), true); - UIRadioButton onlyManualInput = new UIRadioButton( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Manual_Input"), false); - UIRadioButton onlyScanCodeInput = new UIRadioButton( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Scan_Code_Input"), false); - scanCodeAndManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - onlyManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - onlyScanCodeInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - buttonGroup.put(TextInputMode.SUPPORT_SCAN_CODE_And_MANUAL, scanCodeAndManualInput); - buttonGroup.put(TextInputMode.ONLY_SUPPORT_MANUAL, onlyManualInput); - buttonGroup.put(TextInputMode.ONLY_SUPPORT_SCAN_CODE, onlyScanCodeInput); - buttonGroup.add(scanCodeAndManualInput); - buttonGroup.add(onlyManualInput); - buttonGroup.add(onlyScanCodeInput); - panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); - panel.add(scanCodeAndManualInput); - panel.add(onlyManualInput); - panel.add(onlyScanCodeInput); - final JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); - panelWrapper.add(panel, BorderLayout.NORTH); - return new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, - panelWrapper); - } - private void bindListeners2Widgets() { reInitAllListeners(); AttributeChangeListener changeListener = new AttributeChangeListener() { @@ -78,14 +48,14 @@ public class ScanCodeMobileDefinePane extends MobileWidgetDefinePane { @Override public void populate(FormDesigner designer) { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) xCreator.toData()).getMobileScanCodeAttr(); - buttonGroup.setSelectButton(mobileScanCodeAttr.getTextInputMode()); + settingPane.populateBean(mobileScanCodeAttr); this.bindListeners2Widgets(); } @Override public void update() { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) xCreator.toData()).getMobileScanCodeAttr(); - mobileScanCodeAttr.setTextInputMode(buttonGroup.getCurrentSelected()); + settingPane.updateBean(mobileScanCodeAttr); DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified(); } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileTextFieldInputSettingPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileTextFieldInputSettingPane.java new file mode 100644 index 000000000..75d924e53 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileTextFieldInputSettingPane.java @@ -0,0 +1,61 @@ +package com.fr.design.widget.ui.designer.mobile.component; + +import com.fr.base.mobile.MobileScanCodeAttr; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import javax.swing.JPanel; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/15 + */ +public class MobileTextFieldInputSettingPane extends BasicBeanPane { + + private final UICheckBox manualInputCheckBox; + private final UICheckBox scanCodeCheckBox; + private final UICheckBox nfcInputCheckBox; + + public MobileTextFieldInputSettingPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel settingPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 5); + manualInputCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Mobile_Manual_Input"), true); + scanCodeCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Mobile_Scan_Code_Input"), true); + nfcInputCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Mobile_NFC_Input"), false); + settingPane.add(manualInputCheckBox); + settingPane.add(scanCodeCheckBox); + settingPane.add(nfcInputCheckBox); + this.add(settingPane, BorderLayout.NORTH); + } + + @Override + public void populateBean(MobileScanCodeAttr ob) { + manualInputCheckBox.setSelected(ob.isSupportManual()); + scanCodeCheckBox.setSelected(ob.isSupportScan()); + nfcInputCheckBox.setSelected(ob.isSupportNFC()); + } + + @Override + public MobileScanCodeAttr updateBean() { + // do nothing + return null; + } + + @Override + public void updateBean(MobileScanCodeAttr ob) { + ob.setSupportManual(manualInputCheckBox.isSelected()); + ob.setSupportScan(scanCodeCheckBox.isSelected()); + ob.setSupportNFC(nfcInputCheckBox.isSelected()); + } + + + @Override + protected String title4PopupWindow() { + return null; + } + +} diff --git a/designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java b/designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java index 12c57280c..412d08744 100644 --- a/designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java +++ b/designer-form/src/test/java/com/fr/design/fit/FormUIModeConfigTest.java @@ -1,5 +1,6 @@ package com.fr.design.fit; +import com.fr.design.mainframe.DesignerUIModeConfig; import org.junit.Assert; import org.junit.Test; @@ -9,14 +10,14 @@ import org.junit.Test; public class FormUIModeConfigTest { @Test public void testSetNewUIMode(){ - DesignerUIModeConfig.getInstance().setNewUIMode(); - Assert.assertTrue(DesignerUIModeConfig.getInstance().newUIMode()); + DesignerUIModeConfig.getInstance().setSimulateWebUIMode(); + Assert.assertTrue(DesignerUIModeConfig.getInstance().simulateWebUIMode()); } @Test public void testSetOldUIMode(){ - Assert.assertTrue(DesignerUIModeConfig.getInstance().newUIMode()); - DesignerUIModeConfig.getInstance().setOldUIMode(); - Assert.assertFalse(DesignerUIModeConfig.getInstance().newUIMode()); + Assert.assertTrue(DesignerUIModeConfig.getInstance().simulateWebUIMode()); + DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); + Assert.assertFalse(DesignerUIModeConfig.getInstance().simulateWebUIMode()); } } diff --git a/designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java b/designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java index eef7eece9..1bbfc3a0a 100644 --- a/designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java +++ b/designer-form/src/test/java/com/fr/design/fit/PXReportLengthUNITTest.java @@ -1,6 +1,7 @@ package com.fr.design.fit; import com.fr.base.ScreenResolution; +import com.fr.design.mainframe.PXReportLengthUNIT; import com.fr.stable.unit.FU; import org.easymock.EasyMock; import org.junit.Assert; diff --git a/designer-form/src/test/java/com/fr/design/fit/PXTest.java b/designer-form/src/test/java/com/fr/design/fit/PXTest.java index 4db3e5e0a..dfc2c425e 100644 --- a/designer-form/src/test/java/com/fr/design/fit/PXTest.java +++ b/designer-form/src/test/java/com/fr/design/fit/PXTest.java @@ -1,6 +1,7 @@ package com.fr.design.fit; import com.fr.base.ScreenResolution; +import com.fr.design.mainframe.PX; import com.fr.invoke.Reflect; import org.easymock.EasyMock; import org.junit.Assert; diff --git a/designer-realize/src/main/java/com/fr/design/actions/cell/BorderAction.java b/designer-realize/src/main/java/com/fr/design/actions/cell/BorderAction.java index a23ec781b..844e4f70b 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/cell/BorderAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/cell/BorderAction.java @@ -3,17 +3,26 @@ */ package com.fr.design.actions.cell; -import javax.swing.JComponent; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - import com.fr.base.BaseUtils; import com.fr.base.CellBorderStyle; +import com.fr.base.NameStyle; +import com.fr.base.Style; import com.fr.design.actions.ElementCaseAction; import com.fr.design.actions.core.ActionFactory; +import com.fr.design.mainframe.ElementCasePane; import com.fr.design.style.BorderUtils; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.StyleProvider; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; -import com.fr.design.mainframe.ElementCasePane; +import javax.swing.JComponent; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.Rectangle; /** * Border. @@ -65,7 +74,44 @@ public class BorderAction extends ElementCaseAction implements ChangeListener { return (JComponent) object; } - public boolean update(ElementCasePane elementCasePane) { + public void resetElementStyleToCustom(StyleProvider provider) { + Style style = provider.getStyle(); + if (style instanceof NameStyle) { + style = ((NameStyle) style).getRealStyle(); + } + provider.setStyle(style); + } + + public void resetSelectedElementsStyleToCustom(ElementCasePane elementCasePane) { + Selection selection = elementCasePane.getSelection(); + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + if (selection instanceof FloatSelection) { + FloatSelection floatSelection = (FloatSelection) selection; + FloatElement selectedFloatElement = elementCase.getFloatElement(floatSelection.getSelectedFloatName()); + resetElementStyleToCustom(selectedFloatElement); + } else { + CellSelection cellSelection = (CellSelection) selection; + int cellRectangleCount = cellSelection.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cellSelection.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement != null) { + resetElementStyleToCustom(cellElement); + }; + } + } + } + } + } + + + public boolean update(ElementCasePane elementCasePane) { + resetSelectedElementsStyleToCustom(elementCasePane); + if (oldCellBorderStyle.isNoneBorderStyle()) { //无边框格式 return BorderUtils.updateCellBorderStyle(elementCasePane, oldCellBorderStyle); diff --git a/designer-realize/src/main/java/com/fr/design/actions/columnrow/ColumnRowSizingAction.java b/designer-realize/src/main/java/com/fr/design/actions/columnrow/ColumnRowSizingAction.java index 794f1febb..f6e6a095a 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/columnrow/ColumnRowSizingAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/columnrow/ColumnRowSizingAction.java @@ -4,7 +4,7 @@ package com.fr.design.actions.columnrow; import com.fr.design.DesignerEnvManager; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.fun.ReportLengthUNITProvider; import com.fr.design.gui.frpane.UnitInputPane; import com.fr.design.gui.frpane.UnitInputPane.ValueNotChangeException; diff --git a/designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java b/designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java index 4c7feab06..d80622b56 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java @@ -5,9 +5,15 @@ import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.WorkSheetDesigner; import com.fr.design.menu.KeySetUtils; import com.fr.design.report.ReportEnginePane; +import com.fr.intelli.record.FocusPoint; +import com.fr.intelli.record.MetricRegistry; +import com.fr.intelli.record.Original; +import com.fr.json.JSONObject; +import com.fr.report.stable.LayerReportAttr; import com.fr.report.worksheet.WorkSheet; public class ReportEngineAttrAction extends ReportComponentAction { @@ -19,7 +25,6 @@ public class ReportEngineAttrAction extends ReportComponentAction currentEditingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + return currentEditingTemplate.getPath(); + } + } + } diff --git a/designer-realize/src/main/java/com/fr/design/actions/utils/ReportActionUtils.java b/designer-realize/src/main/java/com/fr/design/actions/utils/ReportActionUtils.java index 4ea2ad653..620614893 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/utils/ReportActionUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/utils/ReportActionUtils.java @@ -4,6 +4,7 @@ import com.fr.base.Style; import com.fr.design.actions.cell.style.StyleActionInterface; import com.fr.design.mainframe.DesignOperationEvent; import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.utils.gui.AdjustWorkBookDefaultStyleUtils; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; import com.fr.event.EventDispatcher; import com.fr.grid.selection.CellSelection; @@ -15,7 +16,7 @@ import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.ElementCase; import com.fr.report.elementcase.TemplateElementCase; -import java.awt.*; +import java.awt.Rectangle; public class ReportActionUtils { private ReportActionUtils() { @@ -113,7 +114,7 @@ public class ReportActionUtils { CellElement editCellElement = report.getCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); if (editCellElement == null) { - return Style.DEFAULT_STYLE; + return AdjustWorkBookDefaultStyleUtils.adjustCellElement(Style.DEFAULT_STYLE); } //peter:直接返回当前编辑元素的Style diff --git a/designer-realize/src/main/java/com/fr/design/condition/WHPane.java b/designer-realize/src/main/java/com/fr/design/condition/WHPane.java index 0b7fc7c01..5e756ec6f 100644 --- a/designer-realize/src/main/java/com/fr/design/condition/WHPane.java +++ b/designer-realize/src/main/java/com/fr/design/condition/WHPane.java @@ -1,7 +1,7 @@ package com.fr.design.condition; import com.fr.design.DesignerEnvManager; -import com.fr.design.fit.DesignerUIModeConfig; +import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.fun.ReportLengthUNITProvider; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UIBasicSpinner; diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index 0941b4b22..016281bc0 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -2,6 +2,8 @@ package com.fr.design.dscolumn; import com.fr.base.BaseFormula; import com.fr.data.util.SortOrder; +import com.fr.design.border.UITitledBorder; +import com.fr.design.constants.LayoutConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; @@ -12,12 +14,15 @@ import com.fr.design.formula.UIFormula; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.gui.style.TextFormatPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.sort.celldscolumn.CellDSColumnSortPane; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.report.cell.CellElement; import com.fr.report.cell.TemplateCellElement; @@ -29,6 +34,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Arrays; import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.BOTTOM; import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.SPECIFY; @@ -40,30 +46,46 @@ public class DSColumnAdvancedPane extends BasicPane { private SortPane sortPane; private SelectCountPane selectCountPane; private ValuePane valuePane; + private FormatAttrPane formatAttrPane; private UICheckBox horizontalExtendableCheckBox; private UICheckBox verticalExtendableCheckBox; private UICheckBox useMultiplyNumCheckBox; private UISpinner multiNumSpinner; + private JPanel contentPane; public DSColumnAdvancedPane() { this(DSColumnPane.SETTING_ALL); } public DSColumnAdvancedPane(int setting) { - this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - this.setLayout(FRGUIPaneFactory.createBorderLayout()); + initContentPane(setting); + initScrollPane(); + } + + private void initScrollPane() { + ScrollPane scrollPane = new ScrollPane(contentPane); + this.add(scrollPane); + } + + private void initContentPane(int setting) { + contentPane = new JPanel(); + contentPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + contentPane.setLayout(FRGUIPaneFactory.createBorderLayout()); sortPane = new SortPane(); - sortPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order"), null)); + sortPane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order"))); if (setting > DSColumnPane.SETTING_DSRELATED) { selectCountPane = new SelectCountPane(); - selectCountPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Results_Filter"), null)); + selectCountPane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Results_Filter"))); } valuePane = new ValuePane(); - valuePane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Custom_Data_Appearance"), null)); + valuePane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Custom_Data_Appearance"))); + formatAttrPane = new FormatAttrPane(); + JPanel titleBorderedFormatPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Format")); + titleBorderedFormatPane.add(formatAttrPane, BorderLayout.NORTH); JPanel extendablePane = null; if (setting > DSColumnPane.SETTING_DSRELATED) { @@ -96,26 +118,29 @@ public class DSColumnAdvancedPane extends BasicPane { }); } - double[] rowSize = {TableLayout.PREFERRED, TableLayout.PREFERRED, - TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}; - double[] columnSize = {TableLayout.FILL}; - Component[][] components = null; if (setting > DSColumnPane.SETTING_DSRELATED) { components = new Component[][]{ {sortPane}, {selectCountPane}, {valuePane}, + {titleBorderedFormatPane}, {extendablePane}, {multiNumPane} }; } else { components = new Component[][]{ {sortPane}, - {valuePane} + {valuePane}, + {titleBorderedFormatPane} }; } - this.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); + + double[] rowSize = {TableLayout.PREFERRED, TableLayout.PREFERRED, + TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}; + double[] columnSize = {TableLayout.FILL}; + + contentPane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); } @Override @@ -128,8 +153,9 @@ public class DSColumnAdvancedPane extends BasicPane { return; } - sortPane.populate(cellElement); + sortPane.populateBean(cellElement); valuePane.populate(cellElement); + formatAttrPane.populate(cellElement); if (selectCountPane != null) { selectCountPane.populate(cellElement); @@ -177,8 +203,9 @@ public class DSColumnAdvancedPane extends BasicPane { return; } - sortPane.update(cellElement); + sortPane.updateBean(cellElement); valuePane.update(cellElement); + formatAttrPane.update(cellElement); if (selectCountPane != null) { selectCountPane.update(cellElement); @@ -212,66 +239,25 @@ public class DSColumnAdvancedPane extends BasicPane { } } - private static class SortPane extends SortFormulaPane { - private CellElement cellElement; + private static class ScrollPane extends UIScrollPane { + ScrollPane(Component component) { + super(component); + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + } @Override - public void formulaAction() { - if (cellElement == null) { - return; - } - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - - String[] displayNames = DesignTableDataManager.getSelectedColumnNames( - DesignTableDataManager.getEditingTableDataSource(), ((DSColumn) value).getDSName()); - - showFormulaDialog(displayNames); + public Dimension getPreferredSize() { + return new Dimension(DSColumnPane.DEFAULT_DIMENSION.width - 20, DSColumnPane.DEFAULT_DIMENSION.height - 100); } + } - void populate(CellElement cellElement) { - if (cellElement == null) { - return; - } - this.cellElement = cellElement; - - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - DSColumn dSColumn = (DSColumn) value; - - int sort = dSColumn.getOrder(); - this.sortOrderComboBox.setSortOrder(new SortOrder(sort)); - - String sortFormula = dSColumn.getSortFormula(); - sortFormulaTextField.setText(sortFormula); + private static class SortPane extends CellDSColumnSortPane { + SortPane() { + this.setLayout(new FlowLayout(FlowLayout.LEFT)); } - public void update(CellElement cellElement) { - if (cellElement == null) { - return; - } - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - DSColumn dSColumn = (DSColumn) (cellElement.getValue()); - - dSColumn.setOrder(this.sortOrderComboBox.getSortOrder().getOrder()); - //lance:sort formula - - String sText = null; - if (!(sortFormulaTextField.getText() == null || sortFormulaTextField.getText().trim().equals("") || sortFormulaTextField.getText().trim().equals("$$$"))) { - sText = new String(sortFormulaTextField.getText()); - } - if (!(sText == null || sText.length() < 1)) { - dSColumn.setSortFormula(sText); - } else { - dSColumn.setSortFormula(null); - } + protected boolean needSortHeaderPane() { + return false; } } @@ -526,6 +512,36 @@ public class DSColumnAdvancedPane extends BasicPane { } } + public static class FormatAttrPane extends TextFormatPane { + + protected void initLayout() { + JComponent[][] components = new JComponent[][] { {typeComboBox, textField, roundingBox} }; + double[] rowSize = new double[] { TableLayout.FILL }; + double[] columnSize = {TableLayout.PREFERRED, 200, TableLayout.PREFERRED}; + + JPanel settingPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 4, 0); + + addComponents(4, new JComponent[]{settingPane, previewLabel}); + } + + @Override + protected void setRoundingBoxVisible(boolean visible) { + roundingBox.setVisible(visible); + } + + public void populate(CellElement cellElement) { + if (cellElement != null) { + populateBean(cellElement.getStyle()); + } + } + + public void update(CellElement cellElement) { + if (cellElement != null) { + cellElement.setStyle(update(cellElement.getStyle())); + } + } + } + private void checkButtonEnabled() { if (useMultiplyNumCheckBox.isSelected()) { multiNumSpinner.setEnabled(true); diff --git a/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java b/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java deleted file mode 100644 index 811d39af5..000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.fr.design.fit; - - -import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.fit.common.PaintUtils; -import com.fr.design.mainframe.JForm; -import com.fr.grid.CellElementPainter; -import com.fr.report.cell.TemplateCellElement; -import com.fr.report.elementcase.ElementCase; - -import java.awt.Graphics2D; - -/** - * Created by kerry on 2020-04-21 - */ -public class AdaptiveCellElementPainter extends CellElementPainter { - - public void paintContent(Graphics2D g2d, ElementCase report, TemplateCellElement ce, int width, int height, int resolution) { - if (HistoryTemplateListCache.getInstance().getCurrentEditingTemplate() instanceof JForm) { - PaintUtils.paintGridCellContent(g2d, ce, width, height, resolution); - }else { - super.paintContent(g2d, report, ce, width, height, resolution); - } - } - - -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java b/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java new file mode 100644 index 000000000..4f1e88367 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java @@ -0,0 +1,21 @@ +package com.fr.design.fit; + +import com.fr.design.fit.common.NewUIModeRotationDraw; +import com.fr.grid.CellElementPainter; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.PaintUtils; +import com.fr.report.elementcase.ElementCase; + +import java.awt.Graphics2D; + +/** + * Created by kerry on 2020-04-21 + */ +public class NewUIModeCellElementPainter extends CellElementPainter { + + public void paintContent(Graphics2D g2d, ElementCase report, TemplateCellElement ce, int width, int height, int resolution) { + PaintUtils.paintGridCellContent(g2d, ce, width, height, resolution, new NewUIModeRotationDraw()); + } + + +} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/GridHeaderWithBoundMouseHandler.java b/designer-realize/src/main/java/com/fr/design/fit/grid/GridHeaderWithBoundMouseHandler.java deleted file mode 100644 index bd3c73846..000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/GridHeaderWithBoundMouseHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.base.DynamicUnitList; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.grid.GridHeader; -import com.fr.grid.AbstractGridHeaderMouseHandler; -import com.fr.report.elementcase.ElementCase; -import com.fr.report.elementcase.TemplateElementCase; - -import java.awt.event.MouseEvent; - -public abstract class GridHeaderWithBoundMouseHandler extends AbstractGridHeaderMouseHandler{ - protected static final int FUZZY_EDGE = 10; - private int limit; - - public GridHeaderWithBoundMouseHandler(GridHeader gHeader, int limit) { - super(gHeader); - this.limit = limit; - } - - public void setLimit(int limit) { - this.limit = limit; - } - - public int getLimit() { - return limit; - } - - public int getDragIndex(MouseEvent evt) { - ElementCase report = this.getEditingElementCase(); - DynamicUnitList sizeList = getSizeList(report); - - int scrollValue = getScrollValue(this.getElementCasePane()); - int scrollExtent = getScrollExtent(this.getElementCasePane()); - int endValue = scrollValue + scrollExtent + 1; - - int beginValue = getBeginValue(this.getElementCasePane()); - - double tmpSize1 = 0; - double tmpSize2; - double tmpIncreaseSize = 0; - - int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); - - for (int index = beginValue; index < endValue; index++) { - if (index == 0) { - index = scrollValue; - } - - tmpSize1 += tmpIncreaseSize; - tmpIncreaseSize = sizeList.get(index).toPixD(resolution); - tmpSize2 = tmpSize1 + Math.max(1, tmpIncreaseSize); - if (isOnSeparatorLineIncludeZero(evt, tmpSize2, tmpIncreaseSize) || isOnNormalSeparatorLine(evt, tmpSize2)) { - return index; - } - } - return -1; - } - - - public ElementCasePane getElementCasePane() { - return this.gHeader.getElementCasePane(); - } - - public TemplateElementCase getEditingElementCase() { - return this.getElementCasePane().getEditingElementCase(); - } - -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitColumnMouseHandler.java b/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitColumnMouseHandler.java deleted file mode 100644 index 28185bc38..000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitColumnMouseHandler.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.base.DynamicUnitList; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.gui.imenu.UIPopupMenu; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.grid.GridColumn; -import com.fr.grid.GridHeader; -import com.fr.grid.GridUtils; -import com.fr.grid.selection.CellSelection; -import com.fr.grid.selection.Selection; -import com.fr.report.ReportHelper; -import com.fr.report.elementcase.ElementCase; -import com.fr.stable.ColumnRow; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.UNIT; - -import javax.swing.SwingUtilities; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.event.MouseEvent; - -/** - * peter:处理对GridColumn的Mouse事件. - */ -public class GridLimitColumnMouseHandler extends GridHeaderWithBoundMouseHandler { - - - public GridLimitColumnMouseHandler(GridColumn gridColumn, int limit) { - super(gridColumn, limit); - this.resolution = gridColumn.getResolution(); - } - - @Override - protected void resetSelectionByRightButton(ColumnRow selectedCellPoint, Selection cs, ElementCasePane ePane) { - int[] selectedColumns = cs.getSelectedColumns(); - if (selectedColumns.length == 0 - || selectedCellPoint.getColumn() < selectedColumns[0] - || selectedCellPoint.getColumn() > selectedColumns[selectedColumns.length - 1]) { - resetGridSelectionBySelect(selectedCellPoint.getColumn(), ePane); - } - } - - - protected int doChooseFrom() { - return CellSelection.CHOOSE_COLUMN; - } - - @Override - protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { - int tempOldSelectedCellX = editRectangle.x;// editRectangle.x; - - // adjust them to got the correct selected bounds. - if (selectedCellPoint.getColumn() >= editRectangle.x) { - selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow()); - } else { - tempOldSelectedCellX++; - } - - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); - return new Rectangle(Math.min(tempOldSelectedCellX, selectedCellPoint.getColumn()), 0, Math.max(editRectangle.width, Math.abs(tempOldSelectedCellX - - selectedCellPoint.getColumn())), lastRow); - } - - @Override - protected int[] getGridSelectionIndices(CellSelection cs) { - return cs.getSelectedColumns(); - } - - @Override - protected int getScrollValue(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalValue(); - } - - @Override - protected int getScrollExtent(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalExtent(); - } - - @Override - protected int getBeginValue(ElementCasePane casePane) { - return casePane.getGrid().getHorizontalBeginValue(); - } - - @Override - protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { - return selectedCellPoint.getColumn(); - } - - - /** - * Checks whether is on zero separator line. - */ - @Override - protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpWidth2, double tmpIncreaseWidth) { - return tmpIncreaseWidth <= 1 && (evt.getX() >= tmpWidth2 + 2 && (evt.getX() <= tmpWidth2 + SEPARATOR_GAP)); - } - - @Override - protected boolean between(MouseEvent evt, double from, double to) { - return evt.getX() > from && evt.getX() <= to; - } - - /** - * Checks whether is on normal separator line. - */ - @Override - protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpWidth2) { - return (evt.getX() >= tmpWidth2 - 2) && (evt.getX() <= tmpWidth2 + 2); - } - - @Override - protected int evtOffset(MouseEvent evt, int offset) { - return evt.getX() - offset; - } - - @Override - protected DynamicUnitList getSizeList(ElementCase elementCase) { - return ReportHelper.getColumnWidthList(elementCase); - } - - @Override - protected String methodName() { - return "setColumnWidth"; - } - - @Override - protected String getSelectedHeaderTooltip(int selectedColumnCount) { - return selectedColumnCount + "C"; - } - - @Override - protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { - Point convertPoint = new Point(evt.getX(), 0); - SwingUtilities.convertPointToScreen(convertPoint, gHeader); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - convertPoint.x = Math.max(0, Math.min(convertPoint.x - tipPreferredSize.width / 2, screenSize.width - tipPreferredSize.width)); - convertPoint.y = convertPoint.y - tipPreferredSize.height - 2; - - return convertPoint; - } - - @Override - protected void resetGridSelectionBySelect(int column, ElementCasePane ePane) { - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getRow(); - CellSelection cellSelection = new CellSelection(column, 0, 1, lastRow); - cellSelection.setSelectedType(CellSelection.CHOOSE_COLUMN); - ePane.setSelection(cellSelection); - } - - @Override - protected String nameOfMoveCursorGIF() { - return "cursor_hmove"; - } - - @Override - protected String nameOfSelectCursorGIF() { - return "cursor_hselect"; - } - - @Override - protected String nameOfSplitCursorGIF() { - return "cursor_hsplit"; - } - - @Override - protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, - MouseEvent evt, int columnIndex) { - return ElementCasePaneUtil.createColumnPopupMenu(reportPane, evt, columnIndex); - } - - @Override - protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, - int startMultiSelectIndex, int endMultiSelectIndex) { - int lastRow = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getRow(); - gridSelection.setLastRectangleBounds(Math.min(endMultiSelectIndex, startMultiSelectIndex), 0, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1, lastRow); - } - - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); - int dragIndex = getDragIndex(e); - if (Math.abs(e.getX() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { - UNIT oldValue = this.getEditingElementCase().getColumnWidth(dragIndex); - this.getEditingElementCase().setColumnWidth(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getX(), resolution)); - } - this.getElementCasePane().repaint(); - } - -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java b/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java deleted file mode 100644 index ac4a70eab..000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/GridLimitRowMouseHandler.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.base.DynamicUnitList; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.gui.imenu.UIPopupMenu; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.grid.GridHeader; -import com.fr.grid.GridRow; -import com.fr.grid.GridUtils; -import com.fr.grid.selection.CellSelection; -import com.fr.grid.selection.Selection; -import com.fr.report.ReportHelper; -import com.fr.report.elementcase.ElementCase; -import com.fr.stable.ColumnRow; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.UNIT; - -import javax.swing.SwingUtilities; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; - -/** - * peter:处理对GridRow的Mouse事件. - */ -public class GridLimitRowMouseHandler extends GridHeaderWithBoundMouseHandler { - - public GridLimitRowMouseHandler(GridRow gridRow, int limit) { - super(gridRow, limit); - } - - @Override - protected void resetSelectionByRightButton(ColumnRow selectedCellPoint, Selection cs, ElementCasePane ePane) { - int[] selectedRows = cs.getSelectedRows(); - if (selectedRows.length == 0 - || selectedCellPoint.getRow() < selectedRows[0] - || selectedCellPoint.getRow() > selectedRows[selectedRows.length - 1]) { - resetGridSelectionBySelect(selectedCellPoint.getRow(), ePane); - } - } - - - protected int doChooseFrom() { - return CellSelection.CHOOSE_ROW; - } - - @Override - protected int getScrollValue(ElementCasePane casePane) { - return casePane.getGrid().getVerticalValue(); - } - - @Override - protected int getScrollExtent(ElementCasePane casePane) { - return casePane.getGrid().getVerticalExtent(); - } - - @Override - protected int getBeginValue(ElementCasePane casePane) { - return casePane.getGrid().getVerticalBeginValue(); - } - - @Override - protected Rectangle resetSelectedBoundsByShift(Rectangle editRectangle, ColumnRow selectedCellPoint, ElementCasePane reportPane) { - int tempOldSelectedCellY = editRectangle.y;// editRectangle.x; - - // ajust them to got the correct selected bounds. - if (selectedCellPoint.getRow() >= editRectangle.y) { - selectedCellPoint = ColumnRow.valueOf(selectedCellPoint.getColumn(), selectedCellPoint.getRow() + 1); - } else { - tempOldSelectedCellY++; - } - - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); - return new Rectangle(0, Math.min(tempOldSelectedCellY, selectedCellPoint.getRow()), - lastColumn, Math.max(editRectangle.height, Math.abs(tempOldSelectedCellY - selectedCellPoint.getRow()))); - } - - @Override - protected int[] getGridSelectionIndices(CellSelection cs) { - return cs.getSelectedRows(); - } - - @Override - protected int getColumnOrRowByGridHeader(ColumnRow selectedCellPoint) { - return selectedCellPoint.getRow(); - } - - - @Override - protected void resetGridSelectionBySelect(int row, ElementCasePane ePane) { - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(ePane).getColumn(); - CellSelection cellSelection = new CellSelection(0, row, lastColumn, 1); - cellSelection.setSelectedType(CellSelection.CHOOSE_ROW); - ePane.setSelection(cellSelection); - } - - /** - * Checks whether is on zero separator line. - */ - @Override - protected boolean isOnSeparatorLineIncludeZero(MouseEvent evt, double tmpHeight2, double tmpIncreaseHeight) { - return tmpIncreaseHeight <= 1 && (evt.getY() >= tmpHeight2 + 2 && evt.getY() <= tmpHeight2 + SEPARATOR_GAP); - } - - @Override - protected boolean between(MouseEvent evt, double from, double to) { - return evt.getY() > from && evt.getY() <= to; - } - - @Override - protected DynamicUnitList getSizeList(ElementCase elementCase) { - return ReportHelper.getRowHeightList(elementCase); - } - - @Override - protected String methodName() { - return "setRowHeight"; - } - - /** - * Checks whether is on normal separator line. - */ - @Override - protected boolean isOnNormalSeparatorLine(MouseEvent evt, double tmpHeight2) { - return (evt.getY() >= tmpHeight2 - 2) && (evt.getY() <= tmpHeight2 + 2); - } - - @Override - protected int evtOffset(MouseEvent evt, int offset) { - return evt.getY() - offset; - } - - @Override - protected String getSelectedHeaderTooltip(int rowSelectedCount) { - return rowSelectedCount + "R"; - } - - @Override - protected Point getTipLocationByMouseEvent(MouseEvent evt, GridHeader gHeader, Dimension tipPreferredSize) { - Point convertPoint = new Point(0, evt.getY()); - SwingUtilities.convertPointToScreen(convertPoint, gHeader); - - convertPoint.x = convertPoint.x + gHeader.getSize().width + 2; - convertPoint.y = convertPoint.y - tipPreferredSize.height / 2; - - return convertPoint; - } - - @Override - protected String nameOfMoveCursorGIF() { - return "cursor_vmove"; - } - - @Override - protected String nameOfSelectCursorGIF() { - return "cursor_vselect"; - } - - @Override - protected String nameOfSplitCursorGIF() { - return "cursor_vsplit"; - } - - @Override - protected UIPopupMenu createPopupMenu(ElementCasePane reportPane, - MouseEvent evt, int rowIndex) { - return ElementCasePaneUtil.createRowPopupMenu(reportPane, evt, rowIndex); - } - - @Override - protected void resetGridSelectionByDrag(CellSelection gridSelection, ElementCasePane reportPane, - int startMultiSelectIndex, int endMultiSelectIndex) { - int lastColumn = GridUtils.getAdjustLastColumnRowOfReportPane(reportPane).getColumn(); - gridSelection.setLastRectangleBounds(0, Math.min(endMultiSelectIndex, startMultiSelectIndex), lastColumn, Math.abs(startMultiSelectIndex - endMultiSelectIndex) + 1); - - } - - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - int resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); - int dragIndex = getDragIndex(e); - if (Math.abs(e.getY() - getLimit()) < FUZZY_EDGE && dragIndex >= 0) { - UNIT oldValue = this.getEditingElementCase().getRowHeight(dragIndex); - this.getEditingElementCase().setRowHeight(dragIndex, FU.valueOfPix(oldValue.toPixI(resolution) + getLimit() - e.getY(), resolution)); - } - this.getElementCasePane().repaint(); - } -} diff --git a/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java b/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java deleted file mode 100644 index 9a2601aee..000000000 --- a/designer-realize/src/main/java/com/fr/design/fit/grid/NewFormDesignerGridUI.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.fr.design.fit.grid; - -import com.fr.design.designer.creator.XElementCase; -import com.fr.design.fit.AdaptiveCellElementPainter; -import com.fr.design.fit.DesignerUIModeConfig; -import com.fr.design.fit.common.FormDesignerUtil; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.mainframe.FormDesigner; -import com.fr.grid.CellElementPainter; -import com.fr.grid.Grid; -import com.fr.grid.GridColumn; -import com.fr.grid.GridRow; -import com.fr.grid.GridUI; -import com.fr.report.elementcase.TemplateElementCase; -import com.fr.report.worksheet.FormElementCase; -import com.fr.stable.Constants; -import com.fr.stable.GraphDrawHelper; - -import javax.swing.JComponent; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelListener; - - -/** - * Created by kerry on 2020-04-14 - */ -public class NewFormDesignerGridUI extends GridUI { - private GridLimitColumnMouseHandler gridColumnMouseHandler; - private GridLimitRowMouseHandler gridRowMouseHandler; - private AdaptiveGridListener adaptiveGridListener; - private FormDesigner designer; - - public NewFormDesignerGridUI(FormDesigner designer, int resolution) { - super(resolution); - this.designer = designer; - this.setCellElementPainter(new AdaptiveCellElementPainter()); - } - - public void setCellElementPainter(CellElementPainter elementPainter) { - this.painter = elementPainter; - } - - public void paint(Graphics g, JComponent c) { - Graphics2D g2d = (Graphics2D) g; - Grid grid = (Grid) c; - // 取得ElementCasePane.ElementCase - ElementCasePane elementCasePane = grid.getElementCasePane(); - final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); - - super.paint(g, c); - - if (!(elementCase instanceof FormElementCase)) { - return; - } - final Rectangle rectangle = getBoundsLineRect(elementCase, grid); - int width = getScaleWidth(rectangle.width) - columnWidthList.getRangeValue(0, horizontalValue).toPixI(resolution); - int height = getScaleHeight(rectangle.height) - rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution); - drawBoundsLine(g2d, width, height); - addListener(grid, elementCasePane, width, height, rectangle.width, rectangle.height); - } - - private int getScaleWidth(int width) { - return width * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); - - } - - private int getScaleHeight(int height) { - return height * resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); - } - - - /** - * 获取需要画线的矩形大小 - */ - private Rectangle getBoundsLineRect(TemplateElementCase elementCase, Grid grid) { - final Rectangle rectangle = new Rectangle(); - XElementCase xElementCase = FormDesignerUtil.getXelementCase(designer.getRootComponent(), (FormElementCase) elementCase); - if (xElementCase != null) { - rectangle.setBounds(xElementCase.getBounds()); - - //减去内边距的宽和高 - Insets insets = xElementCase.getInsets(); - rectangle.width -= insets.left + insets.right; - rectangle.height -= insets.top + insets.bottom; - - } - return rectangle; - } - - - private void addListener(Grid grid, ElementCasePane elementCasePane, int width, int height, int actualWidth, int actualHeight) { - addGridColumnListener(elementCasePane.getGridColumn(), width); - addGridRowListener(elementCasePane.getGridRow(), height); - addMouseListener(grid, width, height, actualWidth, actualHeight); - } - - - private void drawBoundsLine(Graphics2D g2d, int width, int height) { - g2d.setPaint(Color.black); - g2d.setStroke(GraphDrawHelper.getStroke(Constants.LINE_DASH_DOT)); - g2d.drawLine(0, height, width, height); - g2d.drawLine(width, 0, width, height); - } - - private void removeGridColumnListener(GridColumn column) { - MouseMotionListener[] mouseMotionListeners = column.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof com.fr.grid.GridColumnMouseHandler || mouseMotionListener instanceof GridLimitColumnMouseHandler) { - column.removeMouseMotionListener(mouseMotionListener); - } - } - MouseListener[] mouseListeners = column.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof com.fr.grid.GridColumnMouseHandler || motionListener instanceof GridLimitColumnMouseHandler) { - column.removeMouseListener(motionListener); - } - } - } - - private void removeGridRowListener(GridRow row) { - MouseMotionListener[] mouseMotionListeners = row.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof com.fr.grid.GridRowMouseHandler || mouseMotionListener instanceof GridLimitRowMouseHandler) { - row.removeMouseMotionListener(mouseMotionListener); - } - } - MouseListener[] mouseListeners = row.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof com.fr.grid.GridRowMouseHandler || motionListener instanceof GridLimitRowMouseHandler) { - row.removeMouseListener(motionListener); - } - } - } - - private void removeGridListener(Grid grid) { - MouseMotionListener[] mouseMotionListeners = grid.getMouseMotionListeners(); - for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { - if (mouseMotionListener instanceof AdaptiveGridListener) { - grid.removeMouseMotionListener(mouseMotionListener); - break; - } - } - MouseListener[] mouseListeners = grid.getMouseListeners(); - for (MouseListener motionListener : mouseListeners) { - if (motionListener instanceof AdaptiveGridListener) { - grid.removeMouseListener(motionListener); - break; - } - } - MouseWheelListener[] mouseWheelListeners = grid.getMouseWheelListeners(); - for (MouseWheelListener mouseWheelListener : mouseWheelListeners) { - if (mouseWheelListener instanceof AdaptiveGridListener) { - grid.removeMouseWheelListener(mouseWheelListener); - break; - } - } - } - - private void addGridColumnListener(GridColumn column, int width) { - if (gridColumnMouseHandler != null) { - gridColumnMouseHandler.setLimit(width); - return; - } - removeGridColumnListener(column); - gridColumnMouseHandler = new GridLimitColumnMouseHandler(column, width); - column.addMouseListener(gridColumnMouseHandler); - column.addMouseMotionListener(gridColumnMouseHandler); - } - - - private void addGridRowListener(GridRow row, int height) { - if (gridRowMouseHandler != null) { - gridRowMouseHandler.setLimit(height); - return; - } - removeGridRowListener(row); - gridRowMouseHandler = new GridLimitRowMouseHandler(row, height); - row.addMouseMotionListener(gridRowMouseHandler); - row.addMouseListener(gridRowMouseHandler); - } - - - private void addMouseListener(Grid grid, int width, int height, int actualWidth, int actualHeight) { - if (adaptiveGridListener != null) { - adaptiveGridListener.resetBoundInfo(width, height, actualWidth, actualHeight); - return; - } - removeGridListener(grid); - adaptiveGridListener = new AdaptiveGridListener(grid, width, height, actualWidth, actualHeight); - grid.addMouseMotionListener(adaptiveGridListener); - grid.addMouseListener(adaptiveGridListener); - grid.addMouseWheelListener(adaptiveGridListener); - } - -} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/AbstractAttrPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/AbstractAttrPane.java index 7194700f2..82d6484e2 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/AbstractAttrPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/AbstractAttrPane.java @@ -66,6 +66,10 @@ public abstract class AbstractAttrPane extends AbstractAttrNoScrollPane { }); } + protected int getMaxHeight(){ + return CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; + } + /** * 属性面板的滚动条和内容区域的布局管理类 */ @@ -93,7 +97,7 @@ public abstract class AbstractAttrPane extends AbstractAttrNoScrollPane { @Override public void layoutContainer(Container parent) { - maxHeight = CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; + maxHeight = getMaxHeight(); if ((MAXVALUE - scrollBar.getVisibleAmount()) == 0) { beginY = 0; } else { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java index dbc4269d6..b4ca61729 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java @@ -6,7 +6,7 @@ package com.fr.design.mainframe; import com.fr.base.BaseFormula; import com.fr.base.DynamicUnitList; import com.fr.base.Formula; -import com.fr.base.ScreenResolution; +import com.fr.base.NameStyle; import com.fr.base.Style; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignState; @@ -67,7 +67,6 @@ import com.fr.design.constants.UIConstants; import com.fr.design.designer.EditingState; import com.fr.design.designer.TargetComponent; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fun.ElementUIProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIPopupMenu; @@ -97,6 +96,7 @@ import com.fr.page.PageAttributeGetter; import com.fr.page.ReportPageAttrProvider; import com.fr.poly.creator.PolyElementCasePane; import com.fr.report.ReportHelper; +import com.fr.report.cell.CellElement; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.cellattr.core.RichText; @@ -133,6 +133,7 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.reflect.Constructor; +import java.util.Iterator; import java.util.Set; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; @@ -157,10 +158,10 @@ public abstract class ElementCasePane extends Tar // alex: private boolean supportDefaultParentCalculate = false; // GUI. - private Grid grid; - private GridRow gridRow; - private GridColumn gridColumn; - private GridCorner gridCorner; + protected Grid grid; + protected GridRow gridRow; + protected GridColumn gridColumn; + protected GridCorner gridCorner; private JScrollBar verScrollBar; private JScrollBar horScrollBar; // Visible @@ -175,6 +176,7 @@ public abstract class ElementCasePane extends Tar private CellSelection formatReferencedCell = null; private CellSelection cellNeedTOFormat = null; private FormatBrushAction formatBrushAction; + private boolean repeatSelection = false; private ActionListener keyListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -365,7 +367,6 @@ public abstract class ElementCasePane extends Tar } } - public void setResolution(int resolution) { this.resolution = resolution; } @@ -526,11 +527,17 @@ public abstract class ElementCasePane extends Tar return this.selection.getQuickEditor(this); } + public boolean isRepeatSelection() { + return repeatSelection; + } + + public void setRepeatSelection(boolean repeatSelection) { + this.repeatSelection = repeatSelection; + } + @Override public void setSelection(Selection selection) { - if (!ComparatorUtils.equals(this.selection, selection) - || !ComparatorUtils.equals(EastRegionContainerPane.getInstance().getCellAttrPane(), CellElementPropertyPane.getInstance()) - || DesignModeContext.isAuthorityEditing()) { + if (isEffectiveSelection(selection)) { try { //旧选中内容编辑器释放模板对象 QuickEditor editor = this.selection.getQuickEditorWithoutPopulate(this); @@ -545,6 +552,12 @@ public abstract class ElementCasePane extends Tar } } + private boolean isEffectiveSelection(Selection selection) { + return (isRepeatSelection() || !ComparatorUtils.equals(this.selection, selection)) + || !ComparatorUtils.equals(EastRegionContainerPane.getInstance().getCellAttrPane(), CellElementPropertyPane.getInstance()) + || DesignModeContext.isAuthorityEditing(); + } + public void setOldSelecton(Selection selection) { this.selection = selection; @@ -1374,6 +1387,33 @@ public abstract class ElementCasePane extends Tar return cellNeedTOFormat; } + public void traverseSelectedCellElements(TemplateCellElementVisitor visitor) { + Selection selection = getSelection(); + if (!(selection instanceof CellSelection)) { + return; + } + CellSelection cs = (CellSelection) selection; + TemplateElementCase elementCase = getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + visitor.visit(column, row, cellElement); + } + } + } + } + + public interface TemplateCellElementVisitor { + void visit(int column, int row, TemplateCellElement cellElement); + } + private class ElementCaseEditingState implements EditingState { protected Selection selection; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/HyperlinkGroupPaneActionImpl.java b/designer-realize/src/main/java/com/fr/design/mainframe/HyperlinkGroupPaneActionImpl.java index 71a37e42f..d90b7e8ec 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/HyperlinkGroupPaneActionImpl.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/HyperlinkGroupPaneActionImpl.java @@ -6,6 +6,7 @@ import com.fr.design.designer.TargetComponent; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; +import com.fr.design.utils.gui.AdjustWorkBookDefaultStyleUtils; import com.fr.general.FRFont; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; @@ -82,7 +83,7 @@ public class HyperlinkGroupPaneActionImpl implements HyperlinkGroupPaneActionPro frFont = frFont.applyForeground(Color.blue); frFont = frFont.applyUnderline(Constants.LINE_THIN); } else { - frFont = frFont.applyForeground(Color.black); + frFont = frFont.applyForeground(AdjustWorkBookDefaultStyleUtils.adjustCellElementFontForeground(Color.black)); frFont = frFont.applyUnderline(Constants.LINE_NONE); } editCellElement.setStyle(elementStyle.deriveFRFont(frFont)); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/app/CptApp.java b/designer-realize/src/main/java/com/fr/design/mainframe/app/CptApp.java index d03db956c..e4b85af22 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/app/CptApp.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/app/CptApp.java @@ -73,8 +73,7 @@ class CptApp extends AbstractWorkBookApp { } catch (RemoteDesignPermissionDeniedException exp) { FineLoggerFactory.getLogger().error(Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied") + file, exp); } catch (TplLockedException exp) { - FineLoggerFactory.getLogger().error(file + Toolkit.i18nText("Fine-Design_Basic_Template_Status_Locked"), exp); - TemplateLockedHandler.generateTipAndRefresh(); + throw new RuntimeException(exp); } catch (Exception exp) { FineLoggerFactory.getLogger().error(Toolkit.i18nText("Fine-Design_Report_NS_Exception_ReadError") + file, exp); } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java b/designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java index bcc7d26fb..01b3172bd 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java @@ -119,8 +119,7 @@ class FormApp extends AbstractAppProvider { } catch (RemoteDesignPermissionDeniedException exp) { FineLoggerFactory.getLogger().error(Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied") + file, exp); } catch (TplLockedException exp) { - FineLoggerFactory.getLogger().error(file + Toolkit.i18nText("Fine-Design_Basic_Template_Status_Locked"), exp); - TemplateLockedHandler.generateTipAndRefresh(); + throw new RuntimeException(exp); } catch (Exception exp) { FineLoggerFactory.getLogger().error("Failed to generate frm from " + file, exp); return null; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java index 8a3b2ded4..7a26e53f2 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java @@ -1,17 +1,7 @@ package com.fr.design.mainframe.cell; -import com.fr.design.gui.iscrollbar.UIScrollBar; -import com.fr.design.mainframe.CellElementPropertyPane; -import com.fr.quickeditor.cellquick.layout.CellElementBarLayout; - -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; +import com.fr.design.gui.frpane.AttributeChangeListener; +import com.fr.design.mainframe.AbstractAttrPane; /** * 右侧单元格元素面板抽象类 @@ -20,26 +10,9 @@ import java.awt.event.MouseWheelListener; * @version 2017年7月25日 * @since 9.0 */ -public abstract class AbstractDSCellEditorPane extends JPanel { - - /** - * 滚动条相关配置 - */ - private static final int MAXVALUE = 100; - private static final int TITLE_HEIGHT = 95; - private static final int CONTENT_PANE_WIDTH_GAP = 3; - private static final int SCROLLBAR_WIDTH = 7; - private static final int MOUSE_WHEEL_SPEED = 5; - private int maxHeight = 280; - - private JPanel leftContentPane; - private UIScrollBar scrollBar; - - protected abstract JPanel createContentPane(); +public abstract class AbstractDSCellEditorPane extends AbstractAttrPane { - public abstract String getIconPath(); - - public abstract String title4PopupWindow(); + private static final int FIXED_HEIGHT = 200; /** * 从面板拿数据保存 @@ -51,78 +24,19 @@ public abstract class AbstractDSCellEditorPane extends JPanel { */ public abstract void populate(); - protected void createScrollPane() { - leftContentPane = this.createContentPane(); - this.prepareScrollBar(); - leftContentPane.setBorder(BorderFactory.createMatteBorder(10, 10, 0, 0, this.getBackground())); - - this.setLayout(new CellElementBarLayout(leftContentPane) { - @Override - public void layoutContainer(Container parent) { - maxHeight = CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; - int beginY; - if ((MAXVALUE - scrollBar.getVisibleAmount()) == 0) { - beginY = 0; - } else { - int preferredHeight = leftContentPane.getPreferredSize().height; - int value = scrollBar.getValue(); - beginY = value * (preferredHeight - maxHeight) / (MAXVALUE - scrollBar.getVisibleAmount()); - } - int width = parent.getWidth(); - int height = parent.getHeight(); - if (leftContentPane.getPreferredSize().height > maxHeight) { - leftContentPane.setBounds(0, -beginY, width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, height + beginY); - scrollBar.setBounds(width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, 0, SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP, height); - } else { - leftContentPane.setBounds(0, 0, width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, height); - } - } - }); - this.add(scrollBar); - this.add(leftContentPane); - } - - - private void prepareScrollBar() { - scrollBar = new UIScrollBar(UIScrollBar.VERTICAL) { - @Override - public int getVisibleAmount() { - int preferredHeight = leftContentPane.getPreferredSize().height; - int e = MAXVALUE * (maxHeight) / preferredHeight; - setVisibleAmount(e); - return e; - } - - @Override - public int getMaximum() { - return MAXVALUE; - } - }; - - scrollBar.addAdjustmentListener(new AdjustmentListener() { - - @Override - public void adjustmentValueChanged(AdjustmentEvent e) { - doLayout(); - } - }); - this.addMouseWheelListener(new MouseWheelListener() { - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - int value = scrollBar.getValue(); - value += MOUSE_WHEEL_SPEED * e.getWheelRotation(); - scrollBar.setValue(value); - doLayout(); - } - }); - scrollBar.setPreferredSize(new Dimension(SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP, this.getHeight())); - scrollBar.setBlockIncrement(SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP); - scrollBar.setBorder(BorderFactory.createMatteBorder(0, CONTENT_PANE_WIDTH_GAP, 0, 0, this.getBackground())); - } /** * 释放tc */ protected abstract void release(); + + protected abstract AttributeChangeListener getAttributeChangeListener(); + + public void addAttributeChangeListener() { + this.addAttributeChangeListener(getAttributeChangeListener()); + } + + protected int getMaxHeight() { + return Math.max(super.getMaxHeight() - FIXED_HEIGHT, 0); + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java index d9f8ed633..18675853c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java @@ -2,6 +2,7 @@ package com.fr.design.mainframe.cell.settingpane; import com.fr.design.mainframe.AbstractAttrPane; import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.utils.gui.AdjustWorkBookDefaultStyleUtils; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; @@ -53,6 +54,7 @@ public abstract class AbstractCellAttrPane extends AbstractAttrPane { TemplateCellElement cellElement = elementCase.getTemplateCellElement(cs.getColumn(), cs.getRow()); if (cellElement == null) { cellElement = DefaultThemedTemplateCellElementCase.createInstance(cs.getColumn(), cs.getRow()); + AdjustWorkBookDefaultStyleUtils.adjustCellElement(cellElement); } this.cellElement = cellElement; elementCase.addCellElement(this.cellElement); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java index cd454660d..9549a3a7e 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java @@ -4,7 +4,6 @@ import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.expand.ExpandLeftFatherPane; import com.fr.design.expand.ExpandUpFatherPane; -import com.fr.design.expand.SortExpandAttrPane; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.icheckbox.UICheckBox; @@ -13,6 +12,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; +import com.fr.design.sort.cellexpand.CellExpandSortPane; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.report.cell.TemplateCellElement; @@ -38,11 +38,11 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { private ExpandUpFatherPane rightFatherPane; private UICheckBox horizontalExpandableCheckBox; private UICheckBox verticalExpandableCheckBox; - private SortExpandAttrPane sortAfterExpand; private JPanel layoutPane; private JPanel basicPane; private JPanel seniorPane; private CellExpandExtraAttrPane extraPane; + private CellExpandSortPane cellExpandSortPane; /** @@ -62,7 +62,6 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { rightFatherPane = new ExpandUpFatherPane(); horizontalExpandableCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_ExpandD_Horizontal_Extendable")); verticalExpandableCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_ExpandD_Vertical_Extendable")); - sortAfterExpand = new SortExpandAttrPane(); initAllNames(); return layoutPane(); } @@ -81,8 +80,11 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { seniorPane = new JPanel(); basicPane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Basic"), 223, 24, basicPane()); seniorPane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Advanced"), 223, 24, seniorPane()); + JPanel sortUIExpandablePane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Expend_Sort"), + 223, 24, cellExpandSortPane = new CellExpandSortPane(this)); layoutPane.add(basicPane, BorderLayout.NORTH); layoutPane.add(seniorPane, BorderLayout.CENTER); + layoutPane.add(sortUIExpandablePane, BorderLayout.SOUTH); extraPane = CellExpandExtraAttrPane.getInstance(); @@ -119,16 +121,12 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { private JPanel seniorPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - UILabel expendSort = new UILabel(Toolkit.i18nText("Fine-Design_Report_Expend_Sort"), SwingConstants.LEFT); - JPanel expendSortPane = new JPanel(new BorderLayout()); - expendSortPane.add(expendSort, BorderLayout.NORTH); horizontalExpandableCheckBox.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); verticalExpandableCheckBox.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); Component[][] components = new Component[][]{ new Component[]{null, null}, new Component[]{horizontalExpandableCheckBox, null}, new Component[]{verticalExpandableCheckBox, null}, - new Component[]{expendSortPane, sortAfterExpand}, }; double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p, f}; @@ -169,9 +167,8 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { } } - sortAfterExpand.populate(cellExpandAttr); - extraPane.populate(cellElement); + cellExpandSortPane.populateBean(cellElement); } @@ -217,11 +214,8 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { } } - if (ComparatorUtils.equals(getGlobalName(), Toolkit.i18nText("Fine-Design_Basic_ExpandD_Sort_After_Expand"))) { - sortAfterExpand.update(cellExpandAttr); - } - extraPane.update(cellElement); + cellExpandSortPane.updateBean(cellElement); } /** diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java index a678c501a..ec3c1bd05 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java @@ -1,20 +1,26 @@ package com.fr.design.mainframe.cell.settingpane; +import com.fr.base.CellBorderStyle; +import com.fr.base.NameStyle; import com.fr.base.Style; import com.fr.design.actions.utils.ReportActionUtils; import com.fr.design.constants.UIConstants; +import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.cell.settingpane.style.StylePane; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; import com.fr.design.style.BorderUtils; +import com.fr.design.utils.gui.AdjustWorkBookDefaultStyleUtils; import com.fr.design.utils.gui.GUICoreUtils; - +import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; -import javax.swing.*; +import javax.swing.JFrame; +import javax.swing.JPanel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Rectangle; /** * @author zhou @@ -69,52 +75,57 @@ public class CellStylePane extends AbstractCellAttrPane { @Override public void updateBeans() { - Object[] selectionCellBorderObjects = BorderUtils.createCellBorderObject(elementCasePane); - if (stylePane.getSelectedIndex() == 0) { - Style s = stylePane.updateBean(); - TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); - int cellRectangleCount = cs.getCellRectangleCount(); - for (int rect = 0; rect < cellRectangleCount; rect++) { - Rectangle cellRectangle = cs.getCellRectangle(rect); - for (int j = 0; j < cellRectangle.height; j++) { - for (int i = 0; i < cellRectangle.width; i++) { - int column = i + cellRectangle.x; - int row = j + cellRectangle.y; - TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); - if (cellElement == null) { - cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); - elementCase.addCellElement(cellElement); - } - cellElement.setStyle(s); - } + // 因为存在框选多个单元格的情况,跟随主题切换到自定义的行为似乎不太适合由updateBeans完成,它更像是个工具栏上的Action. + // 但它又会触发updateBeans... + boolean isSwitchToCustomStyleAction = stylePane.isFollowingThemeSettingChanged() && !stylePane.isFollowingTheme(); + if (isSwitchToCustomStyleAction) { + switchCellStylesToCustom(); + return; + } + updateCellStylesByPaneSettings(); + } + + private void switchCellStylesToCustom() { + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + elementCasePane.traverseSelectedCellElements(new ElementCasePane.TemplateCellElementVisitor() { + @Override + public void visit(int column, int row, TemplateCellElement cellElement) { + if (cellElement == null) { + cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); + elementCase.addCellElement(cellElement); + } + Style style = cellElement.getStyle(); + if (style instanceof NameStyle) { + style = ((NameStyle) style).getRealStyle(); + } + if (style == null) { + style = Style.DEFAULT_STYLE; } + cellElement.setStyle(style); } - } else { - TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); - int cellRectangleCount = cs.getCellRectangleCount(); - for (int rect = 0; rect < cellRectangleCount; rect++) { - Rectangle cellRectangle = cs.getCellRectangle(rect); - for (int j = 0; j < cellRectangle.height; j++) { - for (int i = 0; i < cellRectangle.width; i++) { - int column = i + cellRectangle.x; - int row = j + cellRectangle.y; - TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); - if (cellElement == null) { - cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); - elementCase.addCellElement(cellElement); - } - Style style = cellElement.getStyle(); - if (style == null) { - style = Style.DEFAULT_STYLE; - - } - style = stylePane.updateStyle(style); - cellElement.setStyle(style); - } + }); + } + + private void updateCellStylesByPaneSettings() { + Object[] oldSelectionCellBorderObjects = BorderUtils.createCellBorderObject(elementCasePane); + + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + elementCasePane.traverseSelectedCellElements(new ElementCasePane.TemplateCellElementVisitor() { + @Override + public void visit(int column, int row, TemplateCellElement cellElement) { + if (cellElement == null) { + cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); + AdjustWorkBookDefaultStyleUtils.adjustCellElement(cellElement); + elementCase.addCellElement(cellElement); } + Style style = stylePane.updateBean(); + cellElement.setStyle(style); } - // border必须特别处理 - stylePane.updateBorder(selectionCellBorderObjects); + }); + // border必须特别处理 + CellBorderStyle newCellBorderStyle = stylePane.updateBorderStyle(); + if (newCellBorderStyle != null) { + BorderUtils.update(elementCasePane, oldSelectionCellBorderObjects, newCellBorderStyle); } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/CellPredefinedStyleSettingPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/CellPredefinedStyleSettingPane.java index 4f38c8baa..bc246da8c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/CellPredefinedStyleSettingPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/CellPredefinedStyleSettingPane.java @@ -3,15 +3,11 @@ package com.fr.design.mainframe.cell.settingpane.style; import com.fr.base.CellBorderStyle; import com.fr.base.NameStyle; import com.fr.base.Style; -import com.fr.config.predefined.PredefinedCellStyle; -import com.fr.config.predefined.PredefinedCellStyleConfig; -import com.fr.config.predefined.PredefinedStyle; import com.fr.design.actions.utils.ReportActionUtils; import com.fr.design.constants.UIConstants; import com.fr.design.designer.IntervalConstants; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.MultiTabPane; -import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.style.AbstractBasicStylePane; @@ -21,25 +17,20 @@ import com.fr.design.gui.style.FormatPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.predefined.ui.PredefinedStyleSettingPane; import com.fr.design.mainframe.predefined.ui.preview.StyleSettingPreviewPane; import com.fr.design.style.BorderUtils; //import com.fr.predefined.PredefinedPatternStyleManager; -import com.fr.stable.Constants; -import com.fr.stable.StringUtils; import com.fr.third.javax.annotation.Nonnull; import javax.swing.BorderFactory; import javax.swing.JPanel; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * Created by kerry on 2020-09-02 @@ -212,11 +203,9 @@ public class CellPredefinedStyleSettingPane extends PredefinedStyleSettingPane { } public void dealWithBorder() { + dealWithBorder(true); + } + + public void dealWithBorder(boolean onlyInspectTop) { if (reportPane == null) { return; } Object[] fourObjectArray = BorderUtils.createCellBorderObject(reportPane); - if (fourObjectArray != null && fourObjectArray.length % LENGTH_FOUR == 0) { + if (fourObjectArray.length % LENGTH_FOUR == 0) { + CellBorderStyle cellBorderStyle = new CellBorderStyle(); + boolean insideMode = true; if (fourObjectArray.length == LENGTH_FOUR) { - ((BorderPane) paneList.get(ONE_INDEX)).populateBean((CellBorderStyle) fourObjectArray[0], ((Boolean) fourObjectArray[1]).booleanValue(), ((Integer) fourObjectArray[2]).intValue(), - (Color) fourObjectArray[THREE_INDEX]); - } else { - ((BorderPane) paneList.get(ONE_INDEX)).populateBean(new CellBorderStyle(), Boolean.TRUE, Constants.LINE_NONE, - (Color) fourObjectArray[THREE_INDEX]); + cellBorderStyle = (CellBorderStyle) fourObjectArray[0]; + insideMode = (Boolean) fourObjectArray[1]; } + + BorderPane borderPane = (BorderPane) paneList.get(ONE_INDEX); + borderPane.populateBean(cellBorderStyle, insideMode, onlyInspectTop); } } @@ -139,11 +143,8 @@ public class CustomStylePane extends MultiTabPane