From af9894db43e8aa871b2b9ac4b6d3ea79a5766c0b Mon Sep 17 00:00:00 2001 From: kerry Date: Tue, 29 Sep 2020 17:18:24 +0800 Subject: [PATCH 01/45] =?UTF-8?q?REPORT-35149=20=E9=A2=84=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96=E5=8F=8A=E4=B8=8E?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 26 +- .../mainframe/predefined/PatternStyle.java | 4 +- .../predefined/ui/PredefinedStyleBlock.java | 1 + .../ui/PredefinedStyleEditPane.java | 28 +- .../ui/detail/CellStyleListControlPane.java | 225 ++++++++++++ .../ui/detail/CellStyleSettingPane.java | 332 ------------------ .../detail/background/GradientDetailPane.java | 2 +- .../ui/detail/background/ImageDetailPane.java | 28 +- .../cell/CustomPredefinedStylePane.java | 130 +++++-- .../ui/dialog/PredefinedStyleEditDialog.java | 2 +- .../design/designer/creator/XChartEditor.java | 12 + .../fr/design/designer/creator/XCreator.java | 11 +- .../design/designer/creator/XElementCase.java | 7 +- .../creator/XWAbsoluteBodyLayout.java | 4 +- .../design/designer/creator/XWFitLayout.java | 4 +- .../creator/cardlayout/XWTabFitLayout.java | 4 +- .../xpane/FormPredefinedBackgroundPane.java | 2 +- .../PredefinedComponentStyleSettingPane.java | 10 +- .../com/fr/design/mainframe/FormDesigner.java | 5 +- .../fr/design/mainframe/ToolBarButton.java | 4 +- .../AccessibleBodyBackgroundEditor.java | 3 +- .../AccessibleBorderStyleEditor.java | 3 +- .../ui/designer/layout/ComponentStyle.java | 4 +- .../layout/ElementEditorDefinePane.java | 12 +- .../FRAbsoluteBodyLayoutDefinePane.java | 21 +- .../layout/FRFitLayoutDefinePane.java | 15 +- .../actions/cell/GlobalStyleMenuDef.java | 27 +- .../ServerPredefinedStyleAction.java | 5 +- .../style/CellPredefinedStyleSettingPane.java | 7 +- .../src/main/java/com/fr/grid/GridUI.java | 4 + .../com/fr/grid/selection/CellSelection.java | 27 +- 31 files changed, 523 insertions(+), 446 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java delete mode 100644 designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java 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 c1682f9745..6129f87462 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 @@ -82,8 +82,11 @@ import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JOptionPane; +import javax.swing.SwingConstants; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.undo.UndoManager; +import java.awt.Dimension; +import java.awt.FontMetrics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; @@ -96,6 +99,8 @@ import java.awt.BorderLayout; * 报表设计和表单设计的编辑区域(设计器编辑的IO文件) */ public abstract class JTemplate> extends TargetComponent implements ToolBarMenuDockPlus, DesignerProxy { + + private static final int PREDEFINED_ICON_WIDTH = 27; // TODO ALEX_SEP editingFILE这个属性一定要吗?如果非要不可,有没有可能保证不为null private static final int PREFIX_NUM = 3000; private FILE editingFILE = null; @@ -809,7 +814,7 @@ public abstract class JTemplate> return false; } try { - this.getTarget().resetPreferenceStyle(this.getTemplatePredefinedStyle()); + this.getTarget().setPredefinedStyleName(this.getTemplatePredefinedStyle(), false); this.getTarget().export(editingFILE.asOutputStream()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -1309,17 +1314,19 @@ public abstract class JTemplate> for (DesignerFrameUpButtonProvider provider : providers) { uiButtons = ArrayUtils.addAll(uiButtons, provider.getUpButtons(getMenuState())); } - UIButton predefinedBtn = createPreferenceButton(); + UIButton predefinedBtn = createPreDefinedButton(); if (predefinedBtn != null) { uiButtons = ArrayUtils.addAll(uiButtons, new UIButton[]{predefinedBtn}); } return uiButtons; } - protected UIButton createPreferenceButton(){ + private UIButton createPreDefinedButton() { UIButton preferenceButton = new UIButton(BaseUtils.readIcon("/com/fr/design/icon/icon_predefined_style.png")); - preferenceButton.setToolTipText("预定义样式按钮"); + preferenceButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Template_Style")); preferenceButton.setText(getTemplatePredefinedStyle()); + preferenceButton.setAlignmentX(SwingConstants.LEFT); + setPredefinedButtonSize(preferenceButton); preferenceButton.set4ToolbarButton(); preferenceButton.addActionListener(new ActionListener() { @Override @@ -1335,9 +1342,16 @@ public abstract class JTemplate> return preferenceButton; } - public void resetPredefinedStyle(String styleName, UIButton predefinedBtn){ - this.getTarget().resetPreferenceStyle(styleName); + private void setPredefinedButtonSize(UIButton predefinedBtn) { + String text = predefinedBtn.getText(); + FontMetrics metrics = predefinedBtn.getFontMetrics(predefinedBtn.getFont()); + predefinedBtn.setPreferredSize(new Dimension(Math.min(metrics.stringWidth(text) + PREDEFINED_ICON_WIDTH, 100), 20)); + } + + public void resetPredefinedStyle(String styleName, UIButton predefinedBtn) { + this.getTarget().setPredefinedStyleName(styleName, true); predefinedBtn.setText(getTemplatePredefinedStyle()); + setPredefinedButtonSize(predefinedBtn); this.fireTargetModified(); this.repaint(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java index 467c554a4f..94892f75ec 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java @@ -11,13 +11,13 @@ public enum PatternStyle { DARK_STYLE(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Dark_Pattern")) { @Override public PredefinedStyle getPredefinedStyle() { - return PredefinedPatternStyleManager.getInstance().getDarkMode(); + return PredefinedPatternStyleManager.INSTANCE.getDarkMode(); } }, LIGHT_STYLE(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Light_Pattern")) { @Override public PredefinedStyle getPredefinedStyle() { - return PredefinedPatternStyleManager.getInstance().getLightMode(); + return PredefinedPatternStyleManager.INSTANCE.getLightMode(); } }; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java index 18a7e2c492..c4cb09a029 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java @@ -98,6 +98,7 @@ public class PredefinedStyleBlock extends JPanel { PredefinedStylePreviewPane content = new PredefinedStylePreviewPane(0.387, 0.384); content.setPreferredSize(new Dimension(200, 125)); UILabel label = new UILabel(previewObject.getStyleName()); + label.setToolTipText(previewObject.getStyleName()); label.setPreferredSize(new Dimension(167, 25)); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java index ef7644f716..c267082b40 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java @@ -1,8 +1,8 @@ package com.fr.design.mainframe.predefined.ui; -import com.fr.config.ServerPreferenceConfig; import com.fr.config.predefined.PredefinedStyle; import com.fr.config.predefined.PredefinedStyleConfig; +import com.fr.config.ServerPreferenceConfig; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; import com.fr.design.gui.frpane.AttributeChangeListener; @@ -11,11 +11,11 @@ import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.mainframe.predefined.ui.detail.CellStyleSettingPane; import com.fr.design.mainframe.predefined.ui.detail.ChartStyleSettingPane; import com.fr.design.mainframe.predefined.ui.detail.ColorFillStylePane; -import com.fr.design.mainframe.predefined.ui.detail.ComponentStyleSettingPane; import com.fr.design.mainframe.predefined.ui.detail.PredefinedBackgroundSettingPane; +import com.fr.design.mainframe.predefined.ui.detail.ComponentStyleSettingPane; +import com.fr.design.mainframe.predefined.ui.detail.CellStyleListControlPane; import com.fr.design.mainframe.predefined.ui.preview.PredefinedStylePreviewPane; import com.fr.design.utils.DesignUtils; import com.fr.log.FineLoggerFactory; @@ -36,7 +36,7 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { private PredefinedStylePreviewPane previewPane; private UITextField styleNameField; private PredefinedBackgroundSettingPane backgroundSettingPane; - private CellStyleSettingPane cellStyleSettingPane; + private CellStyleListControlPane cellStyleSettingPane; private ComponentStyleSettingPane componentStyleSettingPane; private ChartStyleSettingPane chartStyleSettingPane; private PredefinedStyleSelectPane selectPane; @@ -44,6 +44,8 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { private boolean isPopulating = false; private UITabbedPane uiTabbedPane; + private boolean isLightMode = true; + @Override protected JPanel createContentPane() { JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -167,7 +169,7 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { private JPanel createCellStyleSettingPane() { JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); jPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); - this.cellStyleSettingPane = new CellStyleSettingPane(this); + this.cellStyleSettingPane = new CellStyleListControlPane(); jPanel.add(this.cellStyleSettingPane); return jPanel; } @@ -193,6 +195,7 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { public void populate(PredefinedStyle previewObject) { isPopulating = true; + isLightMode = previewObject.isLightMode(); styleNameField.setText(previewObject.getStyleName()); this.backgroundSettingPane.populateBean(previewObject.getPredefinedBackground()); this.cellStyleSettingPane.populateBean(previewObject.getCellStyleConfig()); @@ -205,6 +208,7 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { public PredefinedStyle update() { PredefinedStyle predefinedStyle = new PredefinedStyle(); + predefinedStyle.setLightMode(isLightMode); predefinedStyle.setStyleName(this.styleNameField.getText()); predefinedStyle.setCellStyleConfig(this.cellStyleSettingPane.updateBean()); predefinedStyle.setPredefinedBackground(this.backgroundSettingPane.updateBean()); @@ -215,11 +219,12 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { } public boolean saveStyle() { - PredefinedStyle previewObject = null; + PredefinedStyle previewObject; try { previewObject = update(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + return false; } if (this.styleNameField.isEnabled() && !validateRepeat(previewObject.getStyleName())) { return false; @@ -231,7 +236,7 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { return true; } - public boolean saveStyle(PredefinedStyle previewObject) { + private boolean saveStyle(PredefinedStyle previewObject) { PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig(); if (StringUtils.isEmpty(previewObject.getStyleName())) { FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(PredefinedStyleEditPane.this), @@ -239,26 +244,27 @@ public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane { return false; } - config.put(previewObject.getStyleName(), previewObject); + config.add(previewObject); ServerPreferenceConfig.getInstance().setPreferenceStyleConfig(config); selectPane.refreshPane(); return true; } public void saveAsNewStyle(String styleName) { - PredefinedStyle previewObject = null; + PredefinedStyle previewObject; try { previewObject = update(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + return; } previewObject.setStyleName(styleName); - if (validateRepeat(styleName)){ + if (validateRepeat(styleName)) { saveStyle(previewObject); } } - private boolean validateRepeat(String styleName){ + private boolean validateRepeat(String styleName) { PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig(); if (config.getStyle(styleName) != null) { FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(PredefinedStyleEditPane.this), diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java new file mode 100644 index 0000000000..e81de14a0e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java @@ -0,0 +1,225 @@ +package com.fr.design.mainframe.predefined.ui.detail; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.config.predefined.PredefinedCellStyle; +import com.fr.config.predefined.PredefinedCellStyleConfig; +import com.fr.design.actions.UpdateAction; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.gui.NameInspector; +import com.fr.design.gui.controlpane.JListControlPane; +import com.fr.design.gui.controlpane.NameObjectCreator; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.ShortCut4JControlPane; +import com.fr.design.gui.controlpane.UnrepeatedNameHelper; +import com.fr.design.gui.ilist.ListModelElement; +import com.fr.design.gui.ilist.ModNameActionListener; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.predefined.ui.detail.cell.CustomPredefinedStylePane; +import com.fr.design.menu.ShortCut; +import com.fr.general.ComparatorUtils; +import com.fr.general.NameObject; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.Nameable; +import com.fr.stable.StringUtils; + +import javax.swing.BorderFactory; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSeparator; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Created by kerry on 2020-09-27 + */ +public class CellStyleListControlPane extends JListControlPane { + private boolean namePermitted = true; + + public CellStyleListControlPane() { + super(); + this.addModNameActionListener(new ModNameActionListener() { + public void nameModed(int index, String oldName, String newName) { + if (ComparatorUtils.equals(oldName, newName) || ComparatorUtils.equals(newName, NameInspector.ILLEGAL_NAME_HOLDER)) { + return; + } + namePermitted = true; + String[] allNames = nameableList.getAllNames(); + allNames[index] = StringUtils.EMPTY; + if (StringUtils.isEmpty(newName)) { + showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Empty_Name"), index); + return; + } + if (isNameRepeated(new List[]{Arrays.asList(allNames)}, newName)) { + showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newName), index); + return; + } + populateSelectedValue(); + } + }); + } + + private void showTipDialogAndReset(String content, int index) { + nameableList.stopEditing(); + + FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CellStyleListControlPane.this), + content, + Toolkit.i18nText("Fine-Design_Basic_Alert"), + JOptionPane.WARNING_MESSAGE); + setIllegalIndex(index); + namePermitted = false; + } + + @Override + public NameableCreator[] createNameableCreators() { + return new NameableCreator[]{new CellStyleNameObjectCreator("新样式", PredefinedCellStyle.class, + CustomPredefinedStylePane.class)}; + } + + @Override + protected String title4PopupWindow() { + return "单元格样式设置面板"; + } + + protected void initComponentPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setCreators(this.createNameableCreators()); + initCardPane(); + JPanel leftPane = getLeftPane(); + JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL); + leftPane.setPreferredSize(new Dimension(70, 0)); + jSeparator.setPreferredSize(new Dimension(2, 0)); + cardPane.setPreferredSize(new Dimension(238, 0)); + cardPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); + JPanel mainSplitPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + mainSplitPane.add(leftPane, BorderLayout.WEST); + mainSplitPane.add(jSeparator, BorderLayout.CENTER); + mainSplitPane.add(cardPane, BorderLayout.EAST); + + this.add(mainSplitPane, BorderLayout.CENTER); + this.checkButtonEnabled(); + } + + protected ShortCut4JControlPane[] createShortcuts() { + return new ShortCut4JControlPane[]{ + shortCutFactory.addItemShortCut(), + new RemoveItemShortCut4JControlPane(new RemoveItemAction()) + }; + } + + + public class RemoveItemShortCut4JControlPane extends ShortCut4JControlPane { + RemoveItemShortCut4JControlPane(ShortCut shortCut) { + this.shortCut = shortCut; + } + + @Override + public void checkEnable() { + ListModelElement selectModel = CellStyleListControlPane.this.getSelectedValue(); + if (selectModel != null) { + NameObject selectNameObject = (NameObject) selectModel.wrapper; + PredefinedCellStyle cellStyle = (PredefinedCellStyle) (selectNameObject.getObject()); + this.shortCut.setEnabled(!cellStyle.isBuiltIn() && !cellStyle.isDefaultStyle()); + } else { + this.shortCut.setEnabled(false); + } + + } + } + + + private class RemoveItemAction extends UpdateAction { + RemoveItemAction() { + this.setName(com.fr.design.i18n.Toolkit.i18nText(("Fine-Design_Basic_Action_Remove"))); + this.setMnemonic('R'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/base/images/cell/control/remove.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + CellStyleListControlPane.this.onRemoveItem(); + } + } + + + class CellStyleNameObjectCreator extends NameObjectCreator { + public CellStyleNameObjectCreator(String menuName, Class clazz, Class updatePane) { + super(menuName, clazz, updatePane); + } + + public Nameable createNameable(UnrepeatedNameHelper helper) { + Constructor constructor = null; + try { + constructor = clazzOfInitCase.getConstructor(); + PredefinedCellStyle cellStyle = constructor.newInstance(); + + cellStyle.setName(menuName); + cellStyle.setStyle(Style.getInstance()); + return new NameObject(helper.createUnrepeatedName(this.menuName()), cellStyle); + + } catch (NoSuchMethodException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } catch (IllegalAccessException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } catch (InstantiationException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } catch (InvocationTargetException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return null; + } + } + + + /** + * Populate + */ + public void populateBean(PredefinedCellStyleConfig ob) { + if (ob == null) { + return; + } + + List nameStyleList = new ArrayList(); + + Iterator styleNameIterator = ob.getStyleNameIterator(); + while (styleNameIterator.hasNext()) { + String name = (String) styleNameIterator.next(); + PredefinedCellStyle tmpStyle = ob.getStyle(name); + + if (tmpStyle != null) { + nameStyleList.add(new NameObject(name, tmpStyle)); + } + } + + NameObject[] nameObjects = new NameObject[nameStyleList.size()]; + nameStyleList.toArray(nameObjects); + + populate(nameObjects); + } + + + public PredefinedCellStyleConfig updateBean() { + Nameable[] nameables = this.update(); + PredefinedCellStyleConfig styleConfig = new PredefinedCellStyleConfig(); + for (int i = 0; i < nameables.length; i++) { + PredefinedCellStyle tmpStyle = (PredefinedCellStyle) ((NameObject) nameables[i]).getObject(); + tmpStyle.setName(nameables[i].getName()); + styleConfig.addStyle(tmpStyle); + } + return styleConfig; + } + + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java deleted file mode 100644 index e16decd245..0000000000 --- a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleSettingPane.java +++ /dev/null @@ -1,332 +0,0 @@ -package com.fr.design.mainframe.predefined.ui.detail; - -import com.fr.base.BaseUtils; -import com.fr.base.Style; -import com.fr.config.predefined.PredefinedCellStyle; -import com.fr.config.predefined.PredefinedCellStyleConfig; -import com.fr.design.beans.BasicBeanPane; -import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.gui.NameInspector; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.ilist.JNameEdList; -import com.fr.design.gui.ilist.ListModelElement; -import com.fr.design.gui.ilist.ModNameActionListener; -import com.fr.design.i18n.Toolkit; -import com.fr.design.icon.IconPathConstants; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.mainframe.predefined.ui.PredefinedStyleEditPane; -import com.fr.design.mainframe.predefined.ui.detail.cell.CustomPredefinedStylePane; -import com.fr.general.ComparatorUtils; -import com.fr.general.NameObject; -import com.fr.report.cell.DefaultTemplateCellElement; -import com.fr.report.cell.TemplateCellElement; -import com.fr.report.core.PaintUtils; -import com.fr.stable.Constants; -import com.fr.stable.Nameable; -import com.fr.stable.StringUtils; - -import javax.swing.DefaultListModel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * Created by kerry on 2020-09-01 - */ -public class CellStyleSettingPane extends BasicBeanPane { - - private StyleListPane styleListPane; - private List customStylePaneList = new ArrayList<>(); - private CardLayout cardLayout; - private JPanel centerPane; - private PredefinedStyleEditPane editPane; - private CellStylePreviewPane previewPane; - private UIButton removeBtn; - - public CellStyleSettingPane(PredefinedStyleEditPane editPane) { - this.editPane = editPane; - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.add(createLeftPane(), BorderLayout.WEST); - this.add(createCenterPane(), BorderLayout.CENTER); - } - - private JPanel createLeftPane() { - JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - panel.setPreferredSize(new Dimension(80, 267)); - panel.add(createToolPane(), BorderLayout.NORTH); - panel.add(createStyleListPane(), BorderLayout.CENTER); - return panel; - } - - private JPanel createToolPane() { - JPanel panel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); - UIButton addBtn = new UIButton(BaseUtils.readIcon(IconPathConstants.ADD_POPMENU_ICON_PATH)); - addBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - styleListPane.addNewStyle(); - } - }); - addBtn.setBorderPainted(false); - panel.add(addBtn); - removeBtn = new UIButton(BaseUtils.readIcon(IconPathConstants.TD_REMOVE_ICON_PATH)); - removeBtn.setBorderPainted(false); - removeBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - styleListPane.removeStyle(); - } - }); - panel.add(removeBtn); - return panel; - } - - private JPanel createStyleListPane() { - JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - jPanel.setPreferredSize(new Dimension(80, 249)); - styleListPane = new StyleListPane(); - jPanel.add(styleListPane); - return jPanel; - } - - private JPanel createCenterPane() { - JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - JPanel titlePreviewPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview")); - titlePreviewPane.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); - previewPane = new CellStylePreviewPane(); - previewPane.setPreferredSize(new Dimension(100, 20)); - titlePreviewPane.setPreferredSize(new Dimension(230, 45)); - titlePreviewPane.add(previewPane); - panel.add(titlePreviewPane, BorderLayout.NORTH); - cardLayout = new CardLayout(); - centerPane = new JPanel(cardLayout); - panel.add(centerPane, BorderLayout.CENTER); - - return panel; - } - - - @Override - public void populateBean(PredefinedCellStyleConfig ob) { - styleListPane.populate(ob); - } - - @Override - public PredefinedCellStyleConfig updateBean() { - return styleListPane.update(); - } - - @Override - protected String title4PopupWindow() { - return null; - } - - class StyleListPane extends JPanel { - private DefaultListModel defaultListModel; - private JNameEdList styleList; - - public StyleListPane() { - defaultListModel = new DefaultListModel(); - styleList = new JNameEdList(defaultListModel) { - public Rectangle createRect(Rectangle rect, int iconWidth) { - return new Rectangle(rect.x, rect.y, rect.width, rect.height); - } - - }; - styleList.setEditable(true); - styleList.addModNameActionListener(new ModNameActionListener() { - public void nameModed(int index, String oldName, String newName) { - if (ComparatorUtils.equals(oldName, newName) || ComparatorUtils.equals(newName, NameInspector.ILLEGAL_NAME_HOLDER)) { - return; - } - String[] allNames = styleList.getAllNames(); - allNames[index] = StringUtils.EMPTY; - if (StringUtils.isEmpty(newName)) { - showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Empty_Name"), index); - return; - } - if (isNameRepeated(new List[]{Arrays.asList(allNames)}, newName)) { - showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newName), index); - styleList.setNameAt("请重新命名", index); - return; - } - styleList.repaint(); - - } - }); - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.add(styleList, BorderLayout.CENTER); - - styleList.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - int selectIndex = styleList.getSelectedIndex(); - Object nameable = styleList.getType(selectIndex); - if (nameable == null) { - return; - } - PredefinedCellStyle cellStyle = ((PredefinedCellStyle) nameable); - cardLayout.show(centerPane, styleList.getNameAt(selectIndex)); - styleList.stopEditing(); - removeBtn.setEnabled(!cellStyle.isBuiltIn()); - if (!validateCouldRename(cellStyle)) { - return; - } - if (e.getClickCount() >= 2 - && SwingUtilities.isLeftMouseButton(e)) { - styleList.editItemAt(styleList.getSelectedIndex()); - } - } - }); - } - - private boolean validateCouldRename(PredefinedCellStyle cellStyle) { - return !cellStyle.isBuiltIn(); - } - - - private void showTipDialogAndReset(String content, int index) { - styleList.stopEditing(); - - FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(StyleListPane.this), - content, - Toolkit.i18nText("Fine-Design_Basic_Alert"), - JOptionPane.WARNING_MESSAGE); - } - - protected boolean isNameRepeated(java.util.List[] list, String name) { - for (int i = 0; i < list.length; i++) { - if (list[i].contains(name)) { - return true; - } - } - return false; - } - - - public void populate(PredefinedCellStyleConfig ob) { - Iterator iterator = ob.getAllStyles().values().iterator(); - while (iterator.hasNext()) { - PredefinedCellStyle entry = iterator.next(); - addStyle(entry); - - } - reset(); - - } - - private void reset() { - if (defaultListModel.getSize() > 0) { - styleList.setSelectedIndex(0); - removeBtn.setEnabled(false); - cardLayout.show(centerPane, styleList.getNameAt(0)); - centerPane.validate(); - Object nameable = styleList.getType(0); - if (nameable == null) { - return; - } - PredefinedCellStyle cellStyle = ((PredefinedCellStyle) nameable); - previewPane.refresh(cellStyle.getStyle()); - } - } - - public PredefinedCellStyleConfig update() { - PredefinedCellStyleConfig config = new PredefinedCellStyleConfig(); - for (int i = 0; i < defaultListModel.getSize(); i++) { - String name = styleList.getNameAt(i); - Style style = customStylePaneList.get(i).updateBean(); - config.addStyle(new PredefinedCellStyle(name, style)); - } - return config; - } - - public void addNewStyle() { - String newStyleName = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"); - if (isNameRepeated(new List[]{Arrays.asList(styleList.getAllNames())}, - newStyleName)) { - showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newStyleName), 0); - return; - } - PredefinedCellStyle cellStyle = new PredefinedCellStyle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"), Style.getInstance()); - addStyle(cellStyle); - } - - public void addStyle(PredefinedCellStyle cellStyle) { - ListModelElement el = new ListCellStyleModelElement(new NameObject(cellStyle.getName(), cellStyle)); - defaultListModel.addElement(el); - CustomPredefinedStylePane customPredefinedStylePane = new CustomPredefinedStylePane(); - customPredefinedStylePane.populateBean(cellStyle.getStyle()); - customPredefinedStylePane.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - previewPane.refresh(customPredefinedStylePane.updateBean()); - editPane.valueChangeAction(); - } - }); - centerPane.add(customPredefinedStylePane, cellStyle.getName()); - customStylePaneList.add(customPredefinedStylePane); - } - - public void removeStyle() { - int selectIndex = styleList.getSelectedIndex(); - defaultListModel.remove(selectIndex); - centerPane.remove(customStylePaneList.get(selectIndex)); - customStylePaneList.remove(selectIndex); - reset(); - } - } - - class ListCellStyleModelElement extends com.fr.design.gui.ilist.ListModelElement { - private Nameable nameable; - - public ListCellStyleModelElement(Nameable nameable) { - super(nameable); - this.nameable = nameable; - } - - @Override - public String toString() { - return this.nameable.getName(); - } - } - - class CellStylePreviewPane extends JPanel { - private TemplateCellElement ce; - - public CellStylePreviewPane() { - ce = new DefaultTemplateCellElement(); - ce.setValue(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_Test_Word")); - } - - public void refresh(Style style) { - this.ce.setStyle(style); - this.repaint(); - } - - @Override - public void paint(Graphics g) { - Style.paintBackground((Graphics2D) g, ce.getStyle(), this.getWidth(), this.getHeight()); - Style.paintBorder((Graphics2D) g, ce.getStyle(), this.getWidth(), this.getHeight()); - PaintUtils.paintGridCellContent((Graphics2D) g, ce, this.getWidth(), this.getHeight(), Constants.FR_PAINT_RESOLUTION); - } - } - - -} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java index dba975cccd..0f4fc225e1 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java @@ -38,7 +38,7 @@ public class GradientDetailPane extends AbstractBackgroundDetailPane { - +public class ImageDetailPane extends AbstractBackgroundDetailPane implements UIObserver { + private UIObserverListener listener; protected ImagePreviewPane previewPane = null; private Style imageStyle = null; private ChangeListener changeListener = null; @@ -49,6 +51,14 @@ public class ImageDetailPane extends AbstractBackgroundDetailPane { - private Style style; - private ChangeListener changeListener; +public class CustomPredefinedStylePane extends MultiTabPane { + private PredefinedCellStyle cellStyle; + private PreviewArea previewArea; + private boolean populating; public CustomPredefinedStylePane() { @@ -41,6 +49,14 @@ public class CustomPredefinedStylePane extends MultiTabPane