Browse Source

Pull request #9204: KERNEL-11517 实现主题色时ClassHelper中遍历搜索对象存在性能问题

Merge in DESIGN/design from ~STARRYI/design:KERNEL-11517 to release/11.0

* commit '44ca0f01134c44e950311e1852289d0d08e35dcb':
  KERNEL-11517 实现主题色时ClassHelper中遍历搜索对象存在性能问题
newui
starryi 3 years ago
parent
commit
4fe74c4382
  1. 10
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  2. 6
      designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java
  3. 5
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java
  4. 144
      designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListExtendedPane.java
  5. 17
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  6. 5
      designer-form/src/main/java/com/fr/design/mainframe/JForm.java
  7. 4
      designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java
  8. 6
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  9. 5
      designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java

10
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -1949,10 +1949,12 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
@Override
public void setTemplateTheme(TemplateTheme newTheme, TemplateThemeCompatible compatible) {
ThemedTemplate.super.setTemplateTheme(newTheme, compatible);
String name = newTheme.getName();
templateThemeButton.setText(name);
templateThemeButton.setToolTipText(name);
if (templateThemeButton != null) {
ThemedTemplate.super.setTemplateTheme(newTheme, compatible);
String name = newTheme.getName();
templateThemeButton.setText(name);
templateThemeButton.setToolTipText(name);
}
}
/**

6
designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java

@ -1,7 +1,12 @@
package com.fr.design.mainframe;
import com.fr.base.io.BaseBook;
import com.fr.base.theme.FineColorGather;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.TemplateThemeCompatible;
import com.fr.file.FILE;
import com.fr.form.main.Form;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
@ -36,6 +41,7 @@ public final class JTemplateFactory {
if (defaultAppExtension.equalsIgnoreCase(fileExtension)) {
JTemplate<?, ?> jt = app.openTemplate(file);
if (jt != null) {
jt.checkAndResetTheme();
return jt;
}
}

5
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe.theme;
import com.fr.base.theme.FineColorFlushUtils;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.TemplateThemeConfig;
import com.fr.base.theme.settings.ThemedCellStyleList;
@ -157,10 +158,8 @@ public abstract class TemplateThemeEditorPane<T extends TemplateTheme> extends J
return container;
}
private void onColorSchemeChanged(List<Color> colors) {
FineColorManager.FineColorReplaceByColorScheme replaceByColorScheme = new FineColorManager.FineColorReplaceByColorScheme(colors);
T theme = updateBean();
FineColorFlushUtils.replaceCacheObject(theme, replaceByColorScheme);
FineColorManager.traverse(theme, replaceByColorScheme);
theme = (T) FineColorSynchronizer.flush(theme, colors);
populateBean4CustomEditors(theme);
this.repaint();
}

144
designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ui/ColorListExtendedPane.java

@ -1,144 +0,0 @@
package com.fr.design.mainframe.theme.edit.ui;
import com.fr.base.theme.FineColorManager;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/8/7
*/
public class ColorListExtendedPane extends JPanel implements MouseListener {
public static final int DEFAULT_COLOR_COUNT = 8;
public static final int DEFAULT_EXTENDED_COUNT = 5;
public static final int DEFAULT_COLOR_SIZE = 16;
public static final int DEFAULT_COLOR_GAP = 3;
public static final ExtendedColorComputer DEFAULT_EXTENDED_COMPUTER = new ExtendedColorComputer() {
@Override
public Color computeExtendedColor(Color color, int index, int count) {
return FineColorManager.computeExtendedColor(color, index, count);
}
};
private final boolean selectable;
private final int colorCount;
private final int extendedCount;
private final int boxSize;
private final int boxGap;
private final List<Color> colorList = new ArrayList<>();
private ExtendedColorComputer extendedColorComputer = DEFAULT_EXTENDED_COMPUTER;
private int selectedColorIndex = -1;
private int selectedExtendedIndex = -1;
public ColorListExtendedPane() {
this(false, DEFAULT_COLOR_COUNT, DEFAULT_EXTENDED_COUNT, DEFAULT_COLOR_SIZE, DEFAULT_COLOR_GAP);
}
public ColorListExtendedPane(boolean selectable, int colorCount, int extendedCount, int boxSize, int boxGap) {
setLayout(FRGUIPaneFactory.createBorderLayout());
this.selectable = selectable;
this.colorCount = Math.max(1, colorCount);
this.extendedCount = extendedCount;
this.boxSize = boxSize;
this.boxGap = boxGap;
for (int i = 0; i < colorCount; i++) {
colorList.add(Color.WHITE);
}
int width = colorCount * boxSize + (colorCount - 1) * boxGap;
int height = extendedCount * boxSize + (extendedCount - 1) * boxGap;
setPreferredSize(new Dimension(width, height));
}
public void populate(List<Color> colors) {
if (colors.size() > 0) {
colorList.clear();
colorList.addAll(colors);
repaint();
}
}
public List<Color> update() {
return new ArrayList<>(colorList);
}
public void setExtendedColorComputer(ExtendedColorComputer extendedColorComputer) {
this.extendedColorComputer = extendedColorComputer;
}
@Override
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int colorIndex = x / (boxSize + boxGap);
int colorX = colorIndex * (boxSize + boxGap);
int extendedIndex = y / boxSize;
int extendedY = extendedIndex * boxSize;
if (colorX <= x && x <= colorX + boxSize && extendedY <= y && y <= extendedY + boxSize) {
selectedColorIndex = colorIndex;
selectedExtendedIndex = extendedIndex;
} else {
selectedColorIndex = -1;
selectedExtendedIndex = -1;
}
repaint();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
public interface ExtendedColorComputer {
Color computeExtendedColor(Color color, int index, int count);
}
@Override
public void paint(Graphics g) {
super.paint(g);
Color oldColor = g.getColor();
for (int i = 0; i < colorCount; i++) {
int x = i * (boxSize + boxGap);
for (int j = 0; j < extendedCount; j++) {
Color color = extendedColorComputer.computeExtendedColor(colorList.get(i), j, extendedCount);
g.setColor(color);
int y = j * (boxSize + boxGap);
g.fillRect(x, y, boxSize, boxSize);
}
}
g.setColor(oldColor);
}
}

17
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -7,6 +7,7 @@ import com.fr.base.chart.BaseChartCollection;
import com.fr.base.theme.FineColorFlushUtils;
import com.fr.base.theme.FineColorGather;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.TemplateThemeAware;
@ -235,13 +236,12 @@ public class XCreatorUtils {
}
public static XCreator createThemedXCreator(Widget widget) {
XCreator creator = createXCreator(widget);
JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
TemplateTheme theme = template.getTemplateTheme();
if (theme instanceof FormTheme) {
setupTemplateTheme(creator, true, (FormTheme) theme, TemplateThemeCompatible.NONE);
widget = setupTemplateTheme(widget, true, (FormTheme) theme, TemplateThemeCompatible.NONE);
}
return creator;
return createXCreator(widget);
}
/**
@ -386,14 +386,12 @@ public class XCreatorUtils {
}
public static void setupTemplateTheme(XCreator container, final boolean forceFollowingTheme, final FormTheme currentTemplateUsingTheme, TemplateThemeCompatible compatible) {
FineColorGather colorGather = new FineColorManager.FineColorReplaceByTheme(currentTemplateUsingTheme, compatible);
Widget root = container.toData();
List<BaseChartCollection> chartCollections = root.getChartCollections();
public static Widget setupTemplateTheme(Widget widget, final boolean forceFollowingTheme, final FormTheme currentTemplateUsingTheme, TemplateThemeCompatible compatible) {
List<BaseChartCollection> chartCollections = widget.getChartCollections();
for (BaseChartCollection chartCollection: chartCollections) {
chartCollection.onTemplateUsingThemeChange(currentTemplateUsingTheme, compatible);
}
Form.traversalWidget(root, new WidgetGather() {
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
TemplateThemeAware<FormTheme> themedWidget = (TemplateThemeAware) widget;
@ -408,8 +406,7 @@ public class XCreatorUtils {
return true;
}
}, TemplateThemeAware.class);
FineColorFlushUtils.replaceCacheObject(container.toData(), colorGather);
FineColorManager.traverse(container.toData(), colorGather);
return (Widget) FineColorSynchronizer.flush(widget, currentTemplateUsingTheme, compatible);
}

5
designer-form/src/main/java/com/fr/design/mainframe/JForm.java

@ -6,6 +6,9 @@ import com.fr.base.Parameter;
import com.fr.base.Releasable;
import com.fr.base.extension.FileExtension;
import com.fr.base.iofile.attr.ExtendSharableAttrMark;
import com.fr.base.theme.FineColorGather;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.TemplateThemeCompatible;
@ -1210,6 +1213,7 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
protected void setUpTheme4NewTemplate() {
super.setUpTheme4NewTemplate();
getTarget().setTemplateTheme(getTarget().getTemplateTheme());
setTarget((Form) FineColorSynchronizer.flush(getTarget(), getTemplateTheme()));
}
@Override
@ -1236,6 +1240,7 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
double slideValue = formArea.getSlideValue();
getTarget().setTemplateTheme(newTheme, compatible);
setTarget((Form) FineColorSynchronizer.flush(getTarget(), newTheme, compatible));
if (HistoryTemplateListCache.getInstance().getCurrentEditingTemplate() == this) {
fireTargetModified(shouldCreateUndoState);

4
designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java

@ -55,7 +55,6 @@ public class ShareComponentUtils {
}
public static XCreator createThemedXCreator(Widget creatorSource, String suitableTemplateThemeName, String shareId, SharableWidgetProvider provider) {
XCreator creator = createXCreator(creatorSource, shareId, provider);
JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
TemplateTheme theme = template.getTemplateTheme();
if (theme instanceof FormTheme) {
@ -64,8 +63,9 @@ public class ShareComponentUtils {
StringUtils.isNotEmpty(suitableTemplateThemeName) &&
StringUtils.equals(theme.getName(), suitableTemplateThemeName) &&
!StringUtils.equals(theme.getName(), themeName4LegacyTemplate);
XCreatorUtils.setupTemplateTheme(creator, false, (FormTheme) theme, isCurrentUsingThemeSuitSharedComponent ? TemplateThemeCompatible.NONE : TemplateThemeCompatible.ABSENT);
creatorSource = XCreatorUtils.setupTemplateTheme(creatorSource, false, (FormTheme) theme, isCurrentUsingThemeSuitSharedComponent ? TemplateThemeCompatible.NONE : TemplateThemeCompatible.ABSENT);
}
XCreator creator = createXCreator(creatorSource, shareId, provider);
return creator;
}

6
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -6,6 +6,9 @@ import com.fr.base.Parameter;
import com.fr.base.ScreenResolution;
import com.fr.base.TRL;
import com.fr.base.extension.FileExtension;
import com.fr.base.theme.FineColorGather;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.ReportTheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.TemplateThemeCompatible;
@ -77,6 +80,7 @@ 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.main.Form;
import com.fr.general.ComparatorUtils;
import com.fr.general.ModuleContext;
import com.fr.grid.Grid;
@ -1289,6 +1293,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
protected void setUpTheme4NewTemplate() {
super.setUpTheme4NewTemplate();
getTarget().setTemplateTheme(getTarget().getTemplateTheme());
setTarget((WorkBook) FineColorSynchronizer.flush(getTarget(), getTemplateTheme()));
}
@ -1308,6 +1313,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
boolean shouldCreateUndoState = compatible == TemplateThemeCompatible.NONE && !StringUtils.equals(oldTheme.getName(), newTheme.getName());
getTarget().setTemplateTheme(newTheme, compatible);
setTarget((WorkBook) FineColorSynchronizer.flush(getTarget(), newTheme, compatible));
if (HistoryTemplateListCache.getInstance().getCurrentEditingTemplate() == this) {
fireTargetModified(shouldCreateUndoState);

5
designer-realize/src/main/java/com/fr/design/mainframe/app/FormApp.java

@ -3,6 +3,9 @@ package com.fr.design.mainframe.app;
import com.fr.base.Parameter;
import com.fr.base.chart.exception.ChartNotFoundException;
import com.fr.base.io.XMLEncryptUtils;
import com.fr.base.theme.FineColorManager;
import com.fr.base.theme.FineColorSynchronizer;
import com.fr.base.theme.TemplateThemeCompatible;
import com.fr.design.DesignerEnvManager;
import com.fr.design.fit.NewJForm;
import com.fr.design.i18n.Toolkit;
@ -124,6 +127,6 @@ class FormApp extends AbstractAppProvider {
FineLoggerFactory.getLogger().error("Failed to generate frm from " + file, exp);
return null;
}
return tpl;
return (Form) FineColorSynchronizer.flush(tpl, tpl.getTemplateTheme());
}
}

Loading…
Cancel
Save