Browse Source
* commit '01acdff5d1bda00b04953aeea07e553eb5043138': REPORT-79767 格式刷复制背景颜色-设计器显示与预览颜色不同bugfix/11.0
superman
2 years ago
5 changed files with 153 additions and 4 deletions
@ -0,0 +1,99 @@
|
||||
package com.fr.design.mainframe.theme.utils; |
||||
|
||||
import com.fr.base.CloneTransformer; |
||||
import com.fr.base.NameStyle; |
||||
import com.fr.base.Style; |
||||
import com.fr.base.theme.FineColorSynchronizer; |
||||
import com.fr.base.theme.TemplateTheme; |
||||
import com.fr.base.theme.settings.ThemedCellStyle; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2022/9/21 |
||||
* |
||||
* 如果粘贴到的模板主题单元格样式与复制过来的主题单元格样式不同,那么需要转换复制过来的主题单元格样式为自定义样式,以保持被复制的样式。 |
||||
* 转换非主题单元格样式内的主题色,以及单元格内的其他主题色,为自定义色 |
||||
*/ |
||||
public class CellElementStylePaster { |
||||
|
||||
/** |
||||
* 为没有实现FCloneable接口的类而抽象出的clone方法包装接口, |
||||
* 使用者需要实现此接口方法,调用真正的clone方法. |
||||
* @param <T> |
||||
*/ |
||||
private interface CloneExecutor<T> { |
||||
T clone(T o) throws Exception; |
||||
} |
||||
private static boolean needConvertThemedStyleToCustomStyle(NameStyle nameStyle) { |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentOpeningOrEditingTemplate(); |
||||
if (template != null) { |
||||
TemplateTheme theme = template.getTemplateTheme(); |
||||
if (theme != null) { |
||||
ThemedCellStyle themedCellStyle = theme.getCellStyleList().find(nameStyle.getName()); |
||||
return !nameStyle.getRealStyle().equals(themedCellStyle.getStyle()); |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
private static <T> T convertThemedColorToCustomColor(T o, CloneExecutor<T> executor) { |
||||
CloneTransformer.setTransformer(new FineColorSynchronizer.FineColorTransformer(fineColor -> { |
||||
fineColor.setHor(-1); |
||||
fineColor.setVer(-1); |
||||
})); |
||||
|
||||
Object cloned = null; |
||||
try { |
||||
cloned = executor.clone(o); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
CloneTransformer.clearTransformer(); |
||||
return (T) cloned; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param cellElement 粘贴到的单元格 |
||||
* @return |
||||
* 如果粘贴到的模板主题单元格样式与复制过来的主题单元格样式不同,那么需要转换复制过来的主题单元格样式为自定义样式,以保持被复制的样式。 |
||||
* 转换非主题单元格样式内的主题色,以及单元格内的其他主题色,为自定义色 |
||||
*/ |
||||
public static TemplateCellElement convertStyleAndColor(TemplateCellElement cellElement) { |
||||
Style backupStyle = cellElement.getStyle(); |
||||
cellElement = convertThemedColorToCustomColor(cellElement, o -> (TemplateCellElement) o.clone()); |
||||
|
||||
Style style = convertStyleAndColor(backupStyle); |
||||
cellElement.setStyle(style); |
||||
|
||||
return cellElement; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param style |
||||
* @return |
||||
* 如果粘贴到的模板主题单元格样式与复制过来的主题单元格样式不同,那么需要转换复制过来的主题单元格样式为自定义样式,以保持被复制的样式。 |
||||
* 转换非主题单元格样式内的主题色 |
||||
*/ |
||||
public static Style convertStyleAndColor(Style style) { |
||||
if (style instanceof NameStyle) { |
||||
NameStyle nameStyle = (NameStyle) style; |
||||
if (needConvertThemedStyleToCustomStyle(nameStyle)) { |
||||
style = nameStyle.getRealStyle(); |
||||
} |
||||
} |
||||
if (!(style instanceof NameStyle)) { |
||||
style = convertThemedColorToCustomColor(style, o -> (Style) o.clone()); |
||||
} |
||||
|
||||
return style; |
||||
} |
||||
} |
Loading…
Reference in new issue