Browse Source

Pull request #7128: REPORT-64080 【主题边框】框选设置样式外边框后,框选小部分切换自定义,之后设计器里显示有问题

Merge in DESIGN/design from ~STARRYI/design:REPORT-62689/feature/x to feature/x

* commit '07be63cef322c072d22a16ae4048640b83b5b196':
  REPORT-64080 【主题边框】框选设置样式外边框后,框选小部分切换自定义,之后设计器里显示有问题
feature/x
starryi 3 years ago
parent
commit
d0f2c920ed
  1. 30
      designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java
  2. 62
      designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java
  3. 39
      designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java

30
designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java

@ -6,6 +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.NameStyle;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import com.fr.base.vcs.DesignerMode;
@ -97,6 +98,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 +135,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;
@ -1374,6 +1377,33 @@ public abstract class ElementCasePane<T extends TemplateElementCase> 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;

62
designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java

@ -1,22 +1,23 @@
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.gui.style.BorderPane;
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.GUICoreUtils;
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;
/**
* @author zhou
@ -71,29 +72,56 @@ public class CellStylePane extends AbstractCellAttrPane {
@Override
public void updateBeans() {
Object[] selectionCellBorderObjects = BorderUtils.createCellBorderObject(elementCasePane);
// 因为存在框选多个单元格的情况,跟随主题切换到自定义的行为似乎不太适合由updateBeans完成,它更像是个工具栏上的Action.
// 但它又会触发updateBeans...
boolean isSwitchToCustomStyleAction = stylePane.isFollowingThemeSettingChanged() && !stylePane.isFollowingTheme();
if (isSwitchToCustomStyleAction) {
switchCellStylesToCustom();
return;
}
updateCellStylesByPaneSettings();
}
private void switchCellStylesToCustom() {
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);
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 = stylePane.updateBean();
Style style = cellElement.getStyle();
if (style instanceof NameStyle) {
style = ((NameStyle) style).getRealStyle();
}
if (style == null) {
style = Style.DEFAULT_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);
elementCase.addCellElement(cellElement);
}
Style style = stylePane.updateBean();
cellElement.setStyle(style);
}
});
// border必须特别处理
CellBorderStyle cellBorderStyle = stylePane.updateBorderStyle();
if (cellBorderStyle != null) {
BorderUtils.update(elementCasePane, selectionCellBorderObjects, cellBorderStyle);
CellBorderStyle newCellBorderStyle = stylePane.updateBorderStyle();
if (newCellBorderStyle != null) {
BorderUtils.update(elementCasePane, oldSelectionCellBorderObjects, newCellBorderStyle);
}
}

39
designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java

@ -51,6 +51,7 @@ public class StylePane extends BasicPane implements UIObserver {
private final List<UIObserverListener> observerListeners = new ArrayList<>();
private Style backupStyleFromPopulating = Style.DEFAULT_STYLE;
private boolean isFollowingThemeSettingChanged = false;
public StylePane() {
followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS);
@ -77,6 +78,7 @@ public class StylePane extends BasicPane implements UIObserver {
followingThemeButtonGroup.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
isFollowingThemeSettingChanged = true;
AttributeChangeUtils.changeComposedUI(StylePane.this, false, new AttributeChangeUtils.UIChangeAction() {
@Override
public void changeComposedUI() {
@ -85,6 +87,7 @@ public class StylePane extends BasicPane implements UIObserver {
}
});
fireStateChanged();
isFollowingThemeSettingChanged = false;
}
});
@ -103,6 +106,14 @@ public class StylePane extends BasicPane implements UIObserver {
cardLayout.show(contentPane, FOLLOWING_THEME_STRING_ARRAYS[selectedIndex]);
if (!isFollowingTheme) {
// 对于同一个单元格,跟随主题切换到自定义,自定义中的配置与其保持一致
syncCustomStylePaneBySelectedNameStyle();
} else {
// 对于同一个单元格,自定义切换到跟随主题,跟随主题选中"默认"样式,并使用默认样式设置选中的单元格
nameStyleListPane.reset();
}
}
private void syncCustomStylePaneBySelectedNameStyle() {
NameStyle lastSelectedNameStyle = nameStyleListPane.updateNameStyle();
if (lastSelectedNameStyle != null) {
Style lastSelectedRealStyle = lastSelectedNameStyle.getRealStyle();
@ -116,10 +127,10 @@ public class StylePane extends BasicPane implements UIObserver {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
}
}
} else {
// 对于同一个单元格,自定义切换到跟随主题,跟随主题选中"默认"样式,并使用默认样式设置选中的单元格
nameStyleListPane.reset();
}
public boolean isFollowingThemeSettingChanged() {
return isFollowingThemeSettingChanged;
}
protected JPanel createTabbedContentPane() {
@ -161,14 +172,22 @@ public class StylePane extends BasicPane implements UIObserver {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style");
}
public void setSelectedIndex(int index) {
public boolean isFollowingTheme() {
return getSelectedIndex() == 0;
}
public void setFollowingTheme(boolean followingTheme) {
setSelectedIndex(followingTheme ? 0 : 1);
}
private void setSelectedIndex(int index) {
if (0 <= index && index < FOLLOWING_THEME_STRING_ARRAYS.length) {
followingThemeButtonGroup.setSelectedIndex(index);
cardLayout.show(contentPane, FOLLOWING_THEME_STRING_ARRAYS[index]);
}
}
public int getSelectedIndex() {
private int getSelectedIndex() {
return followingThemeButtonGroup.getSelectedIndex();
}
@ -185,11 +204,11 @@ public class StylePane extends BasicPane implements UIObserver {
}
public void setSelctedByName(String id) {
setSelectedIndex(ComparatorUtils.equals(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"), id)? 1 : 0);
setFollowingTheme(!ComparatorUtils.equals(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"), id));
}
public CellBorderStyle updateBorderStyle() {
if (getSelectedIndex() == 0) {
if (isFollowingTheme()) {
return nameStyleListPane.updateBorderStyle();
} else if (customStylePane.isBorderPaneSelected()) {
return customStylePane.updateBorderStyle();
@ -199,7 +218,7 @@ public class StylePane extends BasicPane implements UIObserver {
public Style updateBean() {
Style finalStyle = null;
if (getSelectedIndex() == 0) {
if (isFollowingTheme()) {
finalStyle = nameStyleListPane.updateNameStyle();
}
if (finalStyle == null) {
@ -215,7 +234,7 @@ public class StylePane extends BasicPane implements UIObserver {
if (style instanceof NameStyle) {
NameStyle nameStyle = (NameStyle) style;
setSelectedIndex(0);
setFollowingTheme(true);
nameStyleListPane.populateNameStyle(nameStyle);
Style realStyle = nameStyle.getRealStyle();
try {
@ -225,7 +244,7 @@ public class StylePane extends BasicPane implements UIObserver {
e.printStackTrace();
}
} else {
setSelectedIndex(1);
setFollowingTheme(false);
customStylePane.populateBean(style);
}
//单元格配置界面是单例 所以直接在populate的时候把跟随主题的按钮组设置不可见

Loading…
Cancel
Save